예제 #1
0
        static void Main(string[] args)
        {
            SimpleMath math = new SimpleMath();

            math.SetMathHandler((message, result) =>
            {
                Console.WriteLine($"Message: {message}, result: {result}");
            });
            math.Add(10, 10);
        }
예제 #2
0
        static void Main(string[] args)
        {
            // Зарегистрировать делегат как лямбда-выражение.
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((string msg, int result) =>
                             { Console.WriteLine("Message: {0}, Result: {1}", msg, result); });
            m.Add(10, 5);
            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();
        }
        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);
        }
예제 #5
0
파일: Program.cs 프로젝트: usedflax/flaxbox
        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();
        }
예제 #6
0
        static void Main(string[] args)
        {
            //Register with delefate 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);
        }
예제 #7
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();
        }
예제 #8
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();
        }
예제 #9
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();
        }
예제 #10
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());
        }
예제 #11
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();
        }
예제 #12
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();
        }
예제 #13
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();
        }