コード例 #1
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);

            VerySimpleDelegate d = () => { return "Enjoy your string!"; };
            Console.WriteLine(d.Invoke());

            Console.ReadLine();
        }
コード例 #2
0
        private static void Main(string[] args)
        {
            var m = new SimpleMath();

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

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

            Console.WriteLine(d());

            Console.ReadLine();
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //  Register with delegate as a lambda expression
            SimpleMath m = new SimpleMath();

            m.SetMathHandler((msg, result) =>
            {
                Console.WriteLine($"Message: { msg }\tResult: { result }");
            });
            //  this will execute the Lambda expression
            m.Add(10, 10);



            Console.Write("\n\nPress <Enter> to Exit. . .");
            Console.ReadLine();
        }
コード例 #4
0
        static void Main(string[] args)
        {
            //  Register with 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);

            //  Prints "Enjoy your string!" to the console.
            VerySimpleDelegate d = new VerySimpleDelegate(() =>
                                                          { return("Enjoy your string!"); });

            Console.WriteLine("Result from zero param delegate: {0}", d());
        }