Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //initialize delegates
            method1Delegate obj1 = new method1Delegate(method1);
            string          name = obj1.Invoke("kavya");

            Console.WriteLine(name);
            method2Delegate obj2   = new method2Delegate(method2);
            float           result = obj2.Invoke(10, 20, 30);

            Console.WriteLine(result);
            method3Delegate obj3 = new method3Delegate(method3);

            obj3.Invoke("Delegate code");
            method4Delegate obj4 = new method4Delegate(method4);

            obj4.Invoke(10.32f, 20.56f);
            method5Delegate obj5 = new method5Delegate(method5);
            bool            val  = obj5.Invoke(30);

            Console.WriteLine(val);
            method6Delegate obj6 = new method6Delegate(method6);
            bool            str  = obj6.Invoke("jerry");

            Console.WriteLine(str);
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            //initialize delegates
            method1Delegate obj1 = name1 =>
            {
                return("Hello " + name1);
            };
            string name = obj1.Invoke("kavya");

            Console.WriteLine(name);
            method2Delegate obj2 = (a, b, c) =>
            {
                return(a * b * c);
            };
            float result = obj2.Invoke(10, 20, 30);

            Console.WriteLine(result);
            method3Delegate obj3 = str1 =>
            {
                Console.WriteLine("program is: " + str1);
            };

            obj3.Invoke("Delegate code");
            method4Delegate obj4 = (a, b) =>
            {
                Console.WriteLine(a + b);
            };

            obj4.Invoke(10.32f, 20.56f);
            method5Delegate obj5 = value =>
            {
                if (value > 18)
                {
                    return(true);
                }
                return(false);
            };
            bool val = obj5.Invoke(30);

            Console.WriteLine(val);
            method6Delegate obj6 = name1 =>
            {
                if (name1.Length < 5)
                {
                    return(true);
                }
                return(false);
            };
            bool str = obj6.Invoke("jerry");

            Console.WriteLine(str);
            Console.ReadKey();
        }