示例#1
0
        static void Main(string[] args)
        {
            Addnums1Delegate1 obj1 = new Addnums1Delegate1(Addnums1);
            {
                double result = obj1.Invoke(1, 2, 5);
                Console.WriteLine(result);
            }
            CombineStrings1Delegate1 obj2 = new CombineStrings1Delegate1(CombineStrings1);
            {
                string result1 = obj2.Invoke("I ", " am", " good!");
                Console.WriteLine(result1);
            }

            Addnums2Delegate2 obj3 = new Addnums2Delegate2(Addnums2);
            {
                obj3.Invoke(1, 10, 3);
            }
            CombineStrings2Delegate2 obj4 = new CombineStrings2Delegate2(CombineStrings2);
            {
                obj4.Invoke("Hi ", " smile", " More:)");
            }

            CheckLength1Delegate1 obj5 = new CheckLength1Delegate1(CheckLength1);
            {
                bool result1 = obj5.Invoke("Anvitha");
                Console.WriteLine(result1);
            }
            CheckLength2Delegate2 obj6 = new CheckLength2Delegate2(CheckLength2);
            {
                bool result2 = obj6.Invoke("Ajay");
                Console.WriteLine(result2);
            }
        }
        static void Main(string[] args)
        {
            Addnums1Delegate1 obj1 = delegate(int a, int b, int c)
            {
                return(a + b - c);
            };
            CombineStrings1Delegate1 obj2 = delegate(string a, string b, string c)
            {
                return(a + b + c);
            };
            double result = obj1.Invoke(1, 1, 1);

            Console.WriteLine(result);
            string result1 = obj2.Invoke("Anvi", " is", " good!");

            Console.WriteLine(result1);



            Addnums2Delegate2 obj3 = delegate(int a, int b, int c)
            {
                Console.WriteLine(a + b - c);
            };

            obj3.Invoke(1, 10, 3);
            CombineStrings2Delegate2 obj4 = delegate(string a, string b, string c)
            {
                Console.WriteLine(a + b + c);
            };

            obj4.Invoke("Hi ", " smile", " More:)");



            CheckLength1Delegate1 obj5 = delegate(string name)
            {
                if (name.Length > 5)
                {
                    return(true);
                }
                return(false);
            };
            bool check = obj5.Invoke("Anvitha");

            Console.WriteLine(check);
            CheckLength2Delegate2 obj6 = delegate(string namee)
            {
                if (namee.Length == 3)
                {
                    return(true);
                }
                return(false);
            };
            bool check1 = obj6.Invoke("Anvitha");

            Console.WriteLine(check1);
        }