Ejemplo n.º 1
0
        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 ");
            Console.ReadLine();
        }
Ejemplo n.º 2
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();
        }
        static void Main(string[] Args)
        {
            //List to store numbers

            List <int> numbers = new List <int>()
            {
                12, 24, 36, 48, 567, 72, 78, 96, 32, 120, 567, 678
            };

            Console.WriteLine("The elements of List are:");
            //using Lambda expressions to calculate sum of each number in the list(z =>z + z+ z)
            var sum = numbers.Select(z => z + z + z);

            foreach (var num in numbers)
            {
                Console.WriteLine("{0}", num);
            }
            Console.WriteLine();
            //using Lambda expressions to calculate square of each number in the list(x => x*x)

            Addnums2Delegate obj2 = (x, y, z) =>
            {
                Console.WriteLine(x + y + z);
            };

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

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

            Console.ReadKey();
            //using Lambda expressions to calculate cube of each number in the list(x => x*x*x)
            var qube = numbers.Select(y => y * y * y);

            foreach (var number in qube)
            {
                Console.WriteLine("{0}", number);
            }
            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void Main(string[] Args)
        {
            List <int> numbers = new List <int>()
            {
                01, 04, 09, 12, 13, 18, 30
            };

            Console.WriteLine("The elements of List are:");

            var sum = numbers.Select(z => z + z + z);

            foreach (var num in numbers)
            {
                Console.WriteLine("{0}", num);
            }
            Console.WriteLine();


            Addnums2Delegate obj1 = (x, y, z) =>
            {
                Console.WriteLine(x + y + z);
            };

            obj1.Invoke(13, 3.142f, 123456.123456789);

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

            Console.ReadKey();

            var qube = numbers.Select(y => y * y * y);

            foreach (var number in qube)
            {
                Console.WriteLine("{0}", number);
            }
            Console.ReadKey();
        }
Ejemplo n.º 5
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();
        }