static void Main(string[] args)
        {
            MyDel1 avg = (a, b, c) => ((double)a + b + c) / 3.0;

            MyDel2 Add, Sub, Mul, Div;

            Add = (a, b) => a + b;
            Mul = (a, b) => a * b;
            Sub = (a, b) => a - b;
            Div = (a, b) => a / b;

            Random random = new Random();
            MyDel3 rndnum = () => random.Next();

            MyDel3[] arr =
            {
                rndnum,
                rndnum,
                rndnum,
                rndnum,
                rndnum
            };
            MyDel4 myDel4 = a =>
            {
                double sum = 0.0;
                foreach (var f in a)
                {
                    sum += f();
                }
                return(sum / a.Length);
            };

            myDel4(arr);
        }
示例#2
0
        static void Main(string[] args)
        {
            MyAction action = Show;

            action(5, 12);

            MyDel_2 del  = Print;
            string  res  = del(5, 13);
            string  name = "Olga";
            MyDel_2 del2 = delegate(int x, int y){ return(name + "   " + (x + y).ToString()); };

            Console.WriteLine(del2(3, 6));

            MyAction del3 = delegate(int x, int y) { Console.WriteLine(x); };

            MyFoo(delegate(int x, int y) { Console.WriteLine(x * y); });

            MyFoo((x, y) => { Console.WriteLine(x * y); });

            MyDel_2 myDel   = (x, y) => { return((x * y).ToString()); };
            MyDel_2 myDel_2 = (x, y) => (x * y).ToString();
            MyDel3  myDel3  = s => Console.WriteLine(s);
            MyDel4  del4    = () => Console.WriteLine("Hello");

            del4();
            Foo3(() => Console.WriteLine("Hello world"));

            Foo4(() => Console.WriteLine(name));
            Foo4(() => Console.WriteLine("sdkfhsuhfiushf"));
            Foo4(() => { name = name.ToUpper(); name += " Ivanova"; });
            Console.WriteLine(name);

            //--------------------------------------------------------------------//
        }
示例#3
0
 static void Foo3(MyDel4 del)
 {
     del();
 }