Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }