public static void MethodWithCallback(int value1, int value2, Delegate1.Del callback, IMyPrint myPrint) { int sum = value1 + value2; callback($"The sum is: {sum}"); myPrint.WriteDown($"The sum is: {sum} (same idea)"); }
public static void Run() { Console.WriteLine(); Delegate1.Del handler = SubscribeDelegate1.DelegateMethod; handler += SubscribeDelegate1.DelegateMethod; handler += SubscribeDelegate1.DelegateMethod2; handler("First Delegate Test."); NewSubject.WriteLine("Delegate as a parameters - Name: Callback"); IMyPrint myPrint1 = new MyPrint1(); SubscribeDelegate1.MethodWithCallback(1, 2, handler, myPrint1); NewSubject.WriteLine("Delegate as a parameters - Name: Callback 2"); handler -= SubscribeDelegate1.DelegateMethod2; IMyPrint myPrint2 = new MyPrint2(); SubscribeDelegate1.MethodWithCallback(3, 5, handler, myPrint2); }