private static void BasicActionTExamples(int first, int second) { Console.WriteLine($"---------- Begin Action<T> Delegate Example ----------"); // Delegates using Anonymous Functions (again) BizRulesDelegate addDel = (x, y) => x + y; BizRulesDelegate multiplyDel = (x, y) => x * y; var data = new ProcessData(); data.Process(first, second, addDel); // Slow down on purpose - NOT A NORMAL STEP, FOR DEMO ONLY System.Threading.Thread.Sleep(1000); data.Process(first, second, multiplyDel); // Slow down on purpose - NOT A NORMAL STEP, FOR DEMO ONLY System.Threading.Thread.Sleep(1000); // Using Action<T>, Anonymous Functions, and Delegates Action <int, int> myModAction = (x, y) => Console.WriteLine($"{x} mod {y} = {x % y}"); // Slow down on purpose - NOT A NORMAL STEP, FOR DEMO ONLY System.Threading.Thread.Sleep(1000); Action <int, int> myMultiplyAction = (x, y) => Console.WriteLine($"{x} * {y} = {multiplyDel(x, y)}"); data.ProcessAction(first, second, myModAction); data.ProcessAction(first, second, myMultiplyAction); Console.WriteLine($"---------- End Action<T> Delegate Example ----------\n\n"); }
private static void BasicFuncTTResultExamples(int first, int second) { Console.WriteLine($"---------- Begin Func<T,TResult> Delegate Example ----------"); Func <int, int, int> funcAddDel = (x, y) => x + y; Func <int, int, int> funcMultiplyDel = (x, y) => x * y; Func <int, int, int> funcModDel = (x, y) => x % y; var data = new ProcessData(); data.ProcessFunc(first, second, funcAddDel); data.ProcessFunc(first, second, funcMultiplyDel); data.ProcessFunc(first, second, funcModDel); Console.WriteLine($"---------- End Func<T,TResult> Delegate Example ----------"); }