Пример #1
0
        static void Main(string[] args)
        {
            DelCount             delcount = delegate(int a, int b) { return(a + b); };
            Action <int, int>    action   = delegate(int a, int b) { Console.WriteLine("Action" + (a + b)); };
            Action <int, int>    action2  = (a, b) => { Console.WriteLine("Action" + (a + b)); };
            Func <int, int, int> func     = (a, b) => { return(a + b); };
            Func <int, int, int> func2    = (a, b) => { return(a * b); };
            var ProcessCustom             = new ProccessData();

            SumAction(2, 2);
            SumAction4(4, 4);
            SumAction3(2, 2);
            var sum5      = SumAction5();
            var sumaction = SumAction(2, 2);

            sumaction(1, 1);
            ProcessCustom.ProcessAction(3, 3, sumaction);
            ProcessCustom.ProcessAction(3, 3, SumAction4(4, 4));
            ProcessCustom.ProcessAction(3, 3, SumAction3);
            ProcessCustom.ProcessAction(3, 3, sum5);
            ProcessCustom.ProcessAction(3, 3, SumAction2(2, 2));
            ProcessCustom.ProcessDelegate(2, 2, delcount);
            ProcessCustom.ProcessAction(2, 2, action);
            ProcessCustom.ProcessAction(2, 2, action2);
            ProcessCustom.ProcessFun(2, 2, func);
            ProcessCustom.ProcessFun(2, 3, func2);
            Console.Read();
        }
Пример #2
0
        static void Main(string[] args)
        {
            // Here, the ending value for the count
            // is passed to the anonymous method.
            DelCount count = delegate(int end)
            {
                for (int i = 0; i <= end; i++)
                {
                    Console.WriteLine(i);
                }
            };

            count(3);
            Console.WriteLine();
            count(5);
        } // end Main
        static void Main(string[] args)
        {
            // Demonstrate an anonymous method.
            // Here, the code for counting is passed
            // as an anonymous method.
            DelCount count = delegate
            {
                // This is the block of code passed to the delegate.
                for (int i = 0; i <= 5; i++)
                {
                    Console.WriteLine(i);
                }
            }; // notice the semicolon

            count();
        } // end Main
Пример #4
0
        static void Main(string[] args)
        {
            int result;
            // Here, the ending value for the count
            // is passed to the anonymous method.
            // A summation of the count is returned.
            DelCount count = delegate(int end) {
                int sum = 0;
                for (int i = 0; i <= end; i++)
                {
                    Console.WriteLine(i);
                    sum += i;
                }
                return(sum); // return a value from an anonymous method
            };

            result = count(3);
            Console.WriteLine("Summation of 3 is " + result);
            Console.WriteLine();
            result = count(5);
            Console.WriteLine("Summation of 5 is " + result);
        } // end Main()
Пример #5
0
 public void ProcessDelegate(int a, int b, DelCount count)
 {
     Console.WriteLine("Delegate " + count(a, b));
 }