示例#1
0
        static void Main( string[] args )
        {
            // Register w/ delegate as a lambda expression.
            SimpleMath m = new SimpleMath();
            m.SetMathHandler(( msg, result ) =>
            { Console.WriteLine("Message: {0}, Result: {1}", msg, result); });

            // This will execute the lambda expression.
            m.Add(10, 10);
            Console.ReadLine();
        }
示例#2
0
        static void Main(string[] args)
        {
            // Register w/ delegate as a lambda expression.
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((msg, result) =>
                             { Console.WriteLine("Message: {0}, Result: {1}", msg, result); });

            // This will execute the lambda expression.
            m.Add(10, 10);
            Console.ReadLine();
        }
示例#3
0
        static void Main(string[] args)
        {
            SimpleMath simpleMath = new SimpleMath();

            SimpleMath.MathMessage mathMessage = new SimpleMath.MathMessage((m, i) =>
            {
                Console.WriteLine(m);
                Console.WriteLine("The result is:{0}", i);
            });
            simpleMath.SetMathMessage(mathMessage);
            simpleMath.MathAdd(2, 2);
        }
示例#4
0
        static void Main(string[] args)
        {
            // Регистрируем делегат через lambda-выражение
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((msg, result) =>
            {
                Console.WriteLine("Message: {0}, Result: {1}", msg, result);
            });

            m.Add(10, 10);
            Console.ReadLine();
        }
示例#5
0
        static void Main(string[] args)
        {
            //  使用Lambda表达式注册委托
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((msg, result) =>
            {
                Console.WriteLine("Message: {0},Result: {1}", msg, result);
            });

            m.Add(10, 10);
            Console.ReadLine();
        }
示例#6
0
        static void Main(string[] args) {
            SimpleMath m = new SimpleMath();
            m.SetMathHandler((msg, result) => {
                Console.WriteLine("Message: {0}, Result: {1}", msg, result);
            });
            m.Add(10, 11);


            //VerySimpleDelegate d = new VerySimpleDelegate(() => "Enjoy your string");
            VerySimpleDelegate d = () => "Enjoy your string";
            Console.WriteLine(d());

            Console.ReadLine();
        }
示例#7
0
        static void Main(string[] args)
        {
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((msg, result) =>
            {
                Console.WriteLine("Message: {0}, Result: {1}", msg, result);
            });

            m.Add(10, 10);
            Console.ReadLine();

            VerySimpleDelegate d = new VerySimpleDelegate(() => { return(" Text"); });

            Console.WriteLine(d());
        }
示例#8
0
        static void Main(string[] args)
        {
            VerySimpleDelegate d = new VerySimpleDelegate(() => { return("Enjoy your string"); });
            //Register with delegate as a lambda expression
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((msg, result) =>
            {
                Console.WriteLine($"Message {msg}, Result: {result}");
            });

            //This will execute the lambda expression
            m.Add(10, 10);
            Console.WriteLine(d());
            Console.Read();
        }
示例#9
0
        static void Main(string[] args)
        {
            SimpleMath m = new SimpleMath();

            //使用Lambda表达式与有多个参数的委托交互
            m.SetMathHandler((msg, result) =>// (string msg,int result)=>
            {
                Console.WriteLine("Message: {0},Result: {1}", msg, result);
            });
            m.Add(10, 10);
            //与无参数的委托交互可以这样
            VerySimpleDelegate d = new VerySimpleDelegate(() => { return("Enjoy your string!"); });

            Console.WriteLine(d.Invoke());

            Console.ReadLine();
        }
示例#10
0
        static void Main(string[] args)
        {
            Console.WriteLine("***** Lambdas with Multiple or no Params! *****\n");

            // Register w/ delegate as a lambda expression.
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((msg, result) => { Console.WriteLine("Message: {0}, Result: {1}", msg, result); });

            // This will execute the lambda expression.
            m.Add(10, 10);

            VerySimpleDelegate d = new VerySimpleDelegate(() => { return("Enjoy your string!"); });

            Console.WriteLine(d.Invoke());
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            // Register w/ delegate as a lambda expression.
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((msg, result) =>
                             { Console.WriteLine("Lambda Message: {0}, Result: {1}", msg, result); });

            // This will execute the lambda expression.
            m.Add(10, 10);

            m.SetMathHandler(delegate(string msg, int result)
                             { Console.WriteLine("Anonymous Delegate Message: {0}, Result: {1}", msg, result); });
            m.Add(11, 11);

            m.SetMathHandler(ShowResult);
            m.Add(12, 12);
            Console.ReadLine();
        }