示例#1
0
        private static void RunDelegateByAction(ProcessData data)
        {
            //Pass the action delegate now
            Action <int, int> myMultiplyAction = (x, y) => Console.WriteLine("Multiply Action Result: " + (x * y));

            Console.WriteLine("Beginning RunDelegateByAction");
            data.ProcessAction(2, 3, myMultiplyAction);
            Console.WriteLine("Finished RunDelegateByAction");
        }
示例#2
0
        private static void RunDelegateByDelegate(ProcessData data)
        {
            //Create 2 custom instances of BizRulesDelegate
            BizRulesDelegate addDel      = (x, y) => x + y;
            BizRulesDelegate multiplyDel = (x, y) => x * y;

            //Pass the specific delegate that you want to the method, allowing for execution of that specific delegate
            Console.WriteLine("Beginning RunDelegateByDelegate");
            data.Process(2, 3, addDel);
            data.Process(2, 3, multiplyDel);
            Console.WriteLine("Finished RunDelegateByDelegate");
        }
示例#3
0
        private static void RunDelegateByFunc(ProcessData data)
        {
            //Create 2 funcs
            Func <int, int, int> funcAddDel      = (x, y) => x + y;
            Func <int, int, int> funcMultiplyDel = (x, y) => x * y;

            //Pass the specific delegate that you want to the method, allowing for execution of that specific delegate
            Console.WriteLine("Beginning RunDelegateByFunc");
            data.ProcessFunc(2, 3, funcAddDel);
            data.ProcessFunc(2, 3, funcMultiplyDel);
            Console.WriteLine("Finished RunDelegateByFunc");
        }
示例#4
0
        private static void RunDelegateByActionAsync(ProcessData data)
        {
            //Pass the action delegate now
            Action <int, int> myAddAction = (x, y) =>
            {
                System.Threading.Thread.Sleep(3000);
                Console.WriteLine("Add Action Result: " + (x + y));
            };

            Console.WriteLine("Beginning RunDelegateByActionAsync");
            data.ProcessActionAsync(2, 3, myAddAction);
            Console.WriteLine("Finished RunDelegateByActionAsync");
        }
示例#5
0
        private static void RunCustomLambdaDelegates()
        {
            //Create the new class
            var data = new ProcessData();

            RunDelegateByActionAsync(data);

            RunDelegateByDelegate(data);

            RunDelegateByAction(data);

            RunDelegateByFunc(data);
        }