public CancelAction(ActionDel killDel) { kill = killDel; }
static void Main(string[] args) { ActionDel actionDel = null; for (int i = 0; i < 15; i++) { switch (rnd.Next(5)) { // Заполняем массив, дублируя методы в многоадресный делегат case 0: actionDel += MyMath.Addition; // Можно добавлять несколько раз один и тот же метод к делегату break; case 1: actionDel += MyMath.Multiplication; break; case 2: actionDel += MyMath.Exponentiation; break; case 3: actionDel += MyMath.Division; break; case 4: actionDel += MyMath.Subtraction; break; } } actionDel?.Invoke(rnd.Next(-10, 11), rnd.Next(-10, 11)); for (int i = 0; i < 15; i++) { actionDel -= MyMath.Multiplication; actionDel -= MyMath.Division; } Console.WriteLine("\n===================\n"); actionDel?.Invoke(rnd.Next(-10, 11), rnd.Next(-10, 11)); Console.ReadLine(); }
public CommandAction(Command command, ActionDel action, Object args = null) { Command = command; Action = action; Args = args; }
public AlertAction(ActionDel addAlert) { this.addAlert = addAlert; }
public static void PartTwoStart() { int amount = 50; string splitter = "="; Program.center(amount, "Start of The Second Part", "*"); ////////////////////////////////////////////// Program.center(amount, "TryCatchFinally", splitter); DiffExceptions.TryCatchWhen(); try { DiffExceptions.TryFinally(); } catch (Exception ex) { IOService.ShowUserStringWithLineBreak(string.Format("Exception ({0}) wasnt handled because of TryFinally construction", ex.Source)); } Program.center(amount, "ExceptionProperties", splitter); DiffExceptions.ExceptionProperties(); ///////////////////////////////////////////// Program.center(amount, "Delegates", splitter); Delegates delegates = new Delegates(); delegates.FirstExample(); delegates.SecondExample(); delegates.ThirdExample(); delegates.ExampleNumberFour(); delegates.ExampleNumberFive(); delegates.ExampleNumberSix(); delegates.ExampleNumberSeven(); ///////////////////////////////////////////// Program.center(amount, "Using of Delegates", splitter); State state = new State(100); state.RegisterState(ShowState); state.DoTheThing(); state.DoTheThing(); state.UnregisterState(ShowState); state.RegisterState(ShowStateRed); state.DoTheThing(); ///////////////////////////////////////////// Program.center(amount, "Using of AnonimMethods", splitter); AnonimMethods anonim = new AnonimMethods(); anonim.StartExample(); ///////////////////////////////////////////// LambdaFunctions lambda = new LambdaFunctions(); lambda.Start(); ///////////////////////////////////////////// Program.center(amount, "Using of Events", splitter); EventMain.MainEventExample(); ///////////////////////////////////////////// Program.center(amount, "Covariance and ContrCovariance", splitter); StudyCovariance covariance = new StudyCovariance(); covariance.StartExample(); ///////////////////////////////////////////// Program.center(amount, "Delegates Action, Predicate, Func", splitter); ActionDel.StartExample(); ///////////////////////////////////////////// Program.center(amount, "Interfaces", splitter); Interfaces.StartExample(); ///////////////////////////////////////////// Program.center(amount, "The End of The Second Part", "*"); }
public Pin(ActionDel actionEvent) { ActionEvent = actionEvent; }