Пример #1
0
        static void Main(string[] args)
        {
            AddnumsDelegate obj1 = delegate(int x, float y)  //object creation
            {
                return(x + y);
            };
            double result = obj1.Invoke(5, 5.5f); //Invoke Method

            Console.WriteLine(result);

            MultiplyDelegate obj2 = delegate(int x, int y)  //object creation
            {
                return(x + y);
            };
            int result1 = obj2.Invoke(50, 50); //Invoke Method

            Console.WriteLine(result1);

            NamesDelegate obj3 = delegate(string Abhigna)  //object creation
            {
                return(" This " + Abhigna + " my ");
            };
            string result2 = obj3.Invoke("is"); //Invoke Method

            Console.WriteLine(result2);

            WishDelegate obj4 = delegate(String sir) //object creation
            {
                return(" practise " + sir + " yes ");
            };
            string result3 = obj4.Invoke("file "); //Invoke Method

            Console.WriteLine(result3);

            CheckLengthDelegate obj5 = delegate(string name)  //object creation
            {
                if (name.Length > 5)
                {
                    return(true);
                }
                return(false);
            };
            bool check = obj5.Invoke(" sir "); //Invoke Method

            Console.WriteLine(check);

            CheckLength1Delegate obj6 = delegate(string namee) //object creation
            {
                if (namee.Length < 3)
                {
                    return(true);
                }
                return(false);
            };
            bool check1 = obj6.Invoke(" AbhignaThammana ");//Invoke Method

            Console.WriteLine(check1);

            Console.ReadLine();
        }
Пример #2
0
        static void Main(string[] args)
        {
            AddNumber1Delegate del1   = new AddNumber1Delegate(AddNumber1);
            double             Result = del1.Invoke(100, 125.45f, 456.789);

            Console.WriteLine(Result);

            AddNumber2Delegate del2 = new AddNumber2Delegate(AddNumber2);

            del2.Invoke(50, 255.45f, 123.456);

            CheckLengthDelegate del3 = new CheckLengthDelegate(CheckLength);
            bool Status = del3.Invoke("Pranaya");

            Console.WriteLine(Status);

            Console.WriteLine("Using the Generic Delegates");

            Func <int, float, double, double> gDel1 = new Func <int, float, double, double>(AddNumber1);
            double FuncResult = gDel1.Invoke(100, 125.45f, 456.789);

            Console.WriteLine(FuncResult);

            Action <int, float, double> gDel2 = new Action <int, float, double>(AddNumber2);

            gDel2.Invoke(50, 255.45f, 123.456);

            Predicate <string> gDel3 = new Predicate <string>(CheckLength);
            bool StatusUpdate        = gDel3.Invoke("Pranya");

            Console.WriteLine(StatusUpdate);
        }
Пример #3
0
        static void Main(string[] args)
        {
            MultiplynumsDelegate obj = new MultiplynumsDelegate(Multiplynums);
            double result1           = obj.Invoke(10, 20);//New variable to store the value -return type

            Console.WriteLine(result1);
            QuickDelegate p    = new QuickDelegate(Quick);
            string        name = p.Invoke("Mumma");

            Console.WriteLine(name);

            Addnums2Delegate obj2 = new Addnums2Delegate(Addnums2);

            obj2.Invoke(10, 3.142f, 123456.7809738);//Non return type

            GreetingsDelegate w = new GreetingsDelegate(Wishes);

            w.Invoke("wish you ");


            CheckLengthDelegate obj3 = new CheckLengthDelegate(CheckLength);//New variable to store the value -return type

            bool check = obj3.Invoke("Haritha");

            Console.WriteLine(check);

            CheckLengthDelegate o = new CheckLengthDelegate(Value);//New variable to store the value -return type

            bool ch = o.Invoke("Maredapaaly");

            Console.WriteLine(ch);


            Console.ReadLine();
        }
Пример #4
0
        static void Main(string[] args)
        {
            AddnumsDelegate obj1 = delegate(int x, int y)              //object creation
            {
                return(x + y);
            };
            int result = obj1.Invoke(5, 5);

            Console.WriteLine(result);

            MultiplyDelegate obj2 = delegate(int x, float y)              //object creation
            {
                return(x * y);
            };
            double result1 = obj2.Invoke(3, 3.4f);

            Console.WriteLine(result1);

            CheckLengthDelegate obj3 = delegate(string name)
            {
                if (name.Length > 3)
                {
                    return(true);
                }
                return(false);
            };
            bool check = obj3.Invoke("CSHARP");

            Console.WriteLine(check);

            Console.ReadLine();
        }
Пример #5
0
        static void Main(string[] args)
        {
            AddnumsDelegate obj1 = (int x, float y) =>
            {
                return(x + y);
            };
            double result = obj1.Invoke(5, 5.5f);

            Console.WriteLine(result);

            MultiplyDelegate obj2 = (int x, int y) =>
            {
                return(x + y);
            };
            int result1 = obj2.Invoke(50, 50);

            Console.WriteLine(result1);

            NamesDelegate obj3 = was =>
            {
                Console.WriteLine(" This " + was + " my ");
            };

            obj3.Invoke("was");

            WishDelegate obj4 = sir =>
            {
                Console.WriteLine(" my " + sir + "file ");
            };

            obj4.Invoke("practice ");

            CheckLengthDelegate obj5 = name =>
            {
                if (name.Length > 5)
                {
                    return(true);
                }
                return(false);
            };
            bool check = obj5.Invoke(" Sowmya ");

            Console.WriteLine(check);

            CheckLength1Delegate obj6 = namee =>
            {
                if (namee.Length < 3)
                {
                    return(true);
                }
                return(false);
            };
            bool check1 = obj6.Invoke(" Ramyasree ");

            Console.WriteLine(check1);

            Console.ReadLine();
        }
Пример #6
0
        static void Main(string[] args)
        {
            GenericDelegateDemo p    = new GenericDelegateDemo();
            AddNumber1Delegate  obj1 = new AddNumber1Delegate(GenericDelegateDemo.AddNumber1);
            double Result            = obj1.Invoke(100, 125.45f, 456.789);

            Console.WriteLine(Result);
            AddNumber2Delegate obj2 = new AddNumber2Delegate(GenericDelegateDemo.AddNumber2);

            obj2.Invoke(50, 255.45f, 123.456);
            CheckLengthDelegate obj3 = new CheckLengthDelegate(GenericDelegateDemo.CheckLength);
            bool Status = obj3.Invoke("Limon");

            Console.WriteLine(Status);
            Console.WriteLine($"Using gerneric class");
            Func <int, float, double, double> gob1 = new Func <int, float, double, double>(GenericDelegateDemo.AddNumber1);
            var gResult = gob1.Invoke(100, 125.45f, 456.789);

            Console.WriteLine("Genriec: AddNumber1=>" + gResult);

            Action <int, float, double> gob2 = new Action <int, float, double>(GenericDelegateDemo.AddNumber2);

            gob2.Invoke(100, 125.45f, 456.789);
            Predicate <string> golb3 = new Predicate <string>(GenericDelegateDemo.CheckLength);
            var gstatus = golb3.Invoke("limon");

            Console.WriteLine("Status:" + gstatus);
            Console.WriteLine($"End Using gerneric class");
            Console.WriteLine($"LAMBDA and Using gerneric class");
            Func <int, float, double, double> lob1 = (x, y, z) =>
            {
                return(x + y + z);
            };
            double lResult = lob1.Invoke(100, 125.45f, 456.789);

            Console.WriteLine(lResult);

            Action <int, float, double> lob2 = (x, y, z) =>
            {
                Console.WriteLine(x + y + z);
            };

            lob2.Invoke(50, 255.45f, 123.456);
            Console.WriteLine($"End LAMBDA and Using gerneric class");
            Console.ReadKey();
        }
Пример #7
0
        static void Main(string[] args)
        {
            MultiplynumsDelegate obj = new MultiplynumsDelegate(Multiplynums);
            double result1           = obj.Invoke(10, 20);//New variable to store the value -return type

            Console.WriteLine(result1);



            GreetingsDelegate w = new GreetingsDelegate(Wishes);

            w.Invoke("happy grduation ");


            CheckLengthDelegate obj1 = new CheckLengthDelegate(CheckLength);//New variable to store the value -return type

            bool check = obj1.Invoke("dhronacharya");

            Console.WriteLine(check);


            Console.ReadLine();
        }
Пример #8
0
        /*//Method with return value
         * public static int Multiplynums(int x, int y)
         * {
         *  return (x * y);
         * }
         *
         * public static string Quick(string name)
         * {
         *  return "Hello" + name;
         * }
         *
         *
         * //method without return value
         * public static void Addnums2(int x, float y, double z)
         * {
         *  Console.WriteLine(x + y + z);
         * }
         * //method without return value
         * public static void Wishes(string wish)
         * {
         *  Console.WriteLine(wish + " " + "Happy Birthday!!!!!!");
         * }
         *
         *
         * public static bool CheckLength(string name)
         * {
         *  //check the string whose length is greater than 4 should print true else false;
         *  if (name.Length > 4)
         *      return true;
         *  return false;
         * }
         * public static bool value(string name1)
         * {
         *  //check the string whose length is greater than 4 should print true else false;
         *  if (name1.Length < 10)
         *      return true;
         *  return false;
         * }*/
        static void Main(string[] args)
        {
            MultiplynumsDelegate obj = delegate(int x, int y)
            {
                return(x * y);
            };
            double result1 = obj.Invoke(10, 20);//New variable to store the value -return type

            Console.WriteLine(result1);


            QuickDelegate p = delegate(string name1)
            {
                return("Hello" + name1);
            };
            string name = p.Invoke("Yelleti");

            Console.WriteLine(name);

            Addnums2Delegate obj2 = delegate(int x, float y, double z)
            {
                Console.WriteLine(x + y + z);
            };

            obj2.Invoke(10, 3.142f, 123456.7809738);//Non return type

            GreetingsDelegate w = delegate(string wish)
            {
                Console.WriteLine(wish + " " + "Happy Birthday!!!!!!");
            };

            w.Invoke("wish you ");


            CheckLengthDelegate obj3 = delegate(string name1)
            {
                //check the string whose length is greater than 4 should print true else false;
                if (name.Length > 4)
                {
                    return(true);
                }
                return(false);
            };


            bool check = obj3.Invoke("Haritha");

            Console.WriteLine(check);

            CheckLengthDelegate o = delegate(string name1)
            {
                //check the string whose length is greater than 4 should print true else false;
                if (name1.Length < 10)
                {
                    return(true);
                }
                return(false);
            };//New variable to store the value -return type

            bool ch = o.Invoke("Maredapaaly");

            Console.WriteLine(ch);


            Console.ReadLine();
        }