/// <summary>
        /// This is Main method of the class which takes only one arguement as string
        /// </summary>
        /// <param name="args">This is only parameter which must be an string type.</param>
        static void Main(string[] args)
        {
            log4net.Config.BasicConfigurator.Configure();

            Program program = new Program();

            log.Info("Normal method call ");
            log.Info("Sum of the entered numbers :: " + program.Add(30, 20));
            log.Info(SayHello("Sachin"));
            Console.WriteLine();

            log.Info("Usage of delegates...");
            //Creating delegate instance
            AddDelegate addDelegate = new AddDelegate(program.Add);
            SayDelegate sayDelegate = new SayDelegate(SayHello);

            log.Info("Method call using delegates.");
            log.Info("Addition :: " + addDelegate(50, 40));
            log.Info(sayDelegate("Samir"));
            Console.WriteLine();

            log.Info("Add :: " + addDelegate.Invoke(89, 68));
            log.Info(sayDelegate.Invoke("Rahul"));

            Console.Read();
        }
        static void Main(string[] args)
        {
            //Calling methods normally..
            Program p = new Program();

            p.AddNums(100, 25);
            Console.WriteLine(Sayhi("nagesh"));



            //Calling methods by using delegates..
            AddDelegate   ad = new AddDelegate(p.AddNums);
            SayhiDelegate Sh = new SayhiDelegate(Sayhi);

            //Diffrent Way of binding delegate to method.
            SayhiDelegate Sh1 = Program.Sayhi;

            Sh1("Rajabeta");



            ad(100, 20);
            ad.Invoke(150, 20);      //simply works like a method
            string str = Sh("Rakesh");

            Console.WriteLine(str);
        }
        static void Main(string[] args)
        {
            HelloDelegate hd = delegate(string greet)
            {
                Console.WriteLine(greet);
            };

            hd.Invoke("Good Morning!!");
            AddDelegate ad = delegate(double val1, double val2)
            {
                Console.WriteLine(val1 + val2);
            };

            ad.Invoke(123.3446, 2343.44466);
            subDelegate sd = delegate(double val1, double val2)
            {
                Console.WriteLine(val1 - val2);
            };

            sd.Invoke(365.35356, 123.43454);
            MultiplyDelegate md = delegate(int val1, int val2)
            {
                Console.WriteLine(val1 * val2);
            };

            sd.Invoke(125, 132);
            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            //instance
            Program p = new Program();

            p.AddNums(1, 2);

            //static
            Console.WriteLine(Program.StringHello("arun"));

            //2
            AddDelegate addDelegate = new AddDelegate(p.AddNums);
            SayDelegate sayDelegate = new SayDelegate(StringHello);


            Console.WriteLine("Delegates");
            addDelegate(2, 4);
            addDelegate.Invoke(10, 20);
            Console.WriteLine(sayDelegate("ARUN"));
            Console.WriteLine(sayDelegate.Invoke("Arun"));


            Console.WriteLine("Multi cast delegates");
            HelloDelegate helloDelegate = p.SayHello;

            helloDelegate += p.SayHelloWorld;
            helloDelegate();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Enter program no.to execute");
            int i = Convert.ToInt32(Console.ReadLine());

            switch (i)
            {
            case 1:
                ClsDelegates obj1 = new ClsDelegates();
                //obj1.Add(25,30);
                //ClsDelegates.SayHello("anji");
                AddDelegate ad = new AddDelegate(obj1.Add);
                ad.Invoke(10, 20);
                SayDelegate sd = new SayDelegate(ClsDelegates.SayHello);
                sd.Invoke("anji");
                break;

            case 2:
                ClsMultiCastDelegates obj2 = new ClsMultiCastDelegates();
                RectDelegate          rd   = obj2.GetArea;
                rd += obj2.GetParameter;
                rd.Invoke(30.5, 20.5);
                break;

            case 3:
                // ClsAnonymous obj3 = new ClsAnonymous();
                //DelGreetings dg = new DelGreetings(obj3.Greetings);
                //dg(" anji");
                DelGreetings dg = delegate(string name)
                {
                    Console.WriteLine("Hello" + name + " a very good morning");
                };
                dg(" anji");
                break;

            case 4:
                //DelGreetings dg1 = delegate (string name)
                //{
                //    Console.WriteLine("Hello" + name + " a very good morning");
                //};
                DelGreetings dg1 = (name) =>
                {
                    Console.WriteLine("Hello" + name + " a very good morning");
                };
                dg1(" anji");
                break;

            case 5:
                ClsGenericDelegate.CreateDelegate();
                break;

            default:
                break;
            }
            Console.Read();
        }
Exemple #6
0
        static void Main(string[] args)
        {
            Mathematics m = new Mathematics();

            AddDelegate aD = new AddDelegate(m.Add);

            int result = aD.Invoke(4, 5);

            Console.WriteLine(result);      // 9
            Console.WriteLine(aD(5, 12));   // 17
        }
        static void Main(string[] args)
        {
            Delegates2  d  = new Delegates2();
            AddDelegate ad = new AddDelegate(d.AddNums);

            ad(10, 20);
            SayDelegate sd = new SayDelegate(Delegates2.SayHello);
            string      st = sd("world2");

            Console.WriteLine(st);
            ad.Invoke(10, 80);
            Console.Read();
        }
Exemple #8
0
        static void Main(string[] args)
        {
            Program     p = new Program();
            AddDelegate a = new AddDelegate(p.Add);

            a.Invoke(10, 10);

            HelloDelegate h   = new HelloDelegate(Hello);
            string        str = h.Invoke("swamy");

            Console.WriteLine(str);
            Console.ReadLine();
        }
Exemple #9
0
        //public static int Add(int num1,int num2)
        //{
        //    return num1 + num2;
        //}
        static void Main(string[] args)
        {
            //AddDelegate add = new AddDelegate(Add);
            AddDelegate add = delegate(int i, int j)
            {
                return(i + j);
            };

            log.Info("enter numbers");
            int result = add.Invoke(100, 200);

            log.Info(result);
            Console.Read();
        }
        public void Run()
        {
            Add = AddImplementation;
            var result = Add.Invoke(1, 2);

            Console.WriteLine($"Addition result is: {result}");

            Add    = Calculator.Add;
            result = Add(1, 2);
            Console.WriteLine($"Addition result from calculator is: {result}");

            // OUTPUT
            // Addition result is: 3
            // Addition result from calculator is: 3
        }
        static void Main(string[] args)
        {
            AddDelegate del = new AddDelegate(AddNums);

            del.Invoke(1, 2);

            // Delegate instantiation   ann method
            operation obj = delegate
            {
                Console.WriteLine("Anonymous method");
            };

            obj();

            Console.ReadLine();
        }
Exemple #12
0
        static void Main(string[] args)
        {
            Class1 c = new Class1();
            //step2 instantiating delegate
            AddDelegate ad = new AddDelegate(c.AddNums);

            // step 3 calling the delegate
            //ad(100, 50);
            ad.Invoke(100, 30);
            SayDelegate sd = new SayDelegate(Class1.SayHello);
            // string str = sd("Hello");
            string str = sd.Invoke("rahul");

            Console.WriteLine(str);
            Console.ReadLine();
        }
Exemple #13
0
        static void Main(string[] args)
        {
            Program pr = new Program();

            AddDelegate ad = new AddDelegate(pr.AddNum);

            ad.Invoke(10, 20);
            ad(20, 30);
            SayDelegate sd = new SayDelegate(SayHello);

            Console.WriteLine(sd.Invoke("Test"));
            Console.WriteLine(sd("Test2"));
            // pr.AddNum(5,3);
            // Console.WriteLine(SayHello("nmfairus"));
            // Console.WriteLine("Hello World!");
        }
Exemple #14
0
        static void Main(string[] args)
        {
            Delegate p = new Delegate();
            //steep 2
            AddDelegate ad = new AddDelegate(p.Addnums);

            ad(120, 60);
            ad.Invoke(120, 60);

            SayDelegate sd  = new SayDelegate(SayHello);
            string      str = sd("Nitesh kus.mIYY.pIUHhyiaha");

            str = str.ToProper();
            string str1 = sd.Invoke("Nitesh Kushwaha");

            Console.WriteLine(str);
            Console.ReadKey();
        }
Exemple #15
0
        static void Main(string[] args)
        {
            Program     P  = new Program();
            AddDelegate ad = new AddDelegate(P.AddNums); // non-static method not called directly hence called by instance//

            ad.Invoke(100, 500);                         //invoke is anothe method for calling//

            // P.AddNums(10, 20);

            SayDelegate sd  = new SayDelegate(SayHello);   //directly static member can access under static block//
            string      str = sd.Invoke("Atul babar");

            //string Str = Program.SayHello("Atul");


            Console.WriteLine(str);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            //Instantiate the delegate
            GreetingsDelegate obj = delegate(string name)
            {
                return(" Hello " + name + " Very Good Morning ");
            };

            GreetingsDelegate obj1 = delegate(string name)
            {
                return(" This is " + name + " Method ");
            };

            AddDelegate obj2 = delegate(int a, int b)
            {
                return(a + b);
            };

            MulDelegate obj3 = delegate(int x, int y)
            {
                return(x - y);
            };

            //Method is value returning Method
            string str = obj.Invoke("Guys");

            Console.WriteLine(str);

            string str1 = obj1.Invoke("Anonymouus");

            Console.WriteLine(str1);

            int result = obj2.Invoke(10, 20);

            Console.WriteLine(result);

            int result1 = obj3.Invoke(40, 20);

            Console.WriteLine(result1);



            Console.ReadLine();
        }
Exemple #17
0
        static void Main(string[] args)
        {
            //here instatiate a class
            Program p = new Program();
            //p.Addsum(100, 20);

            AddDelegate ad = new AddDelegate(p.Addsum);

            //ad(100, 40); //local variable .

            ad.Invoke(100, 50);
            //here sayhello is static class so call that static class by name

            SayDelegate sd = new SayDelegate(Program.Sayhello);//static member dirctly call another staic block within the class.
            //string str = Program.Sayhello("Om sai");

            string str = sd.Invoke("sai");

            Console.WriteLine(str);
            Console.ReadLine();
        }
Exemple #18
0
        static void Main()
        {
            Delegates p = new Delegates();

            p.AddNum(20, 30);
            string str = SayHello("Karren");//as SayHello is a static method,so calling by using the appropirate name of the class

            Console.WriteLine(str);

            //2) Instantiating the delegate
            Console.WriteLine();
            Console.WriteLine("Calling using the delegate");
            AddDelegate ad = new AddDelegate(p.AddNum); // It isnt a static class ,so we need to class the method by using the instance p
            SayDelegate sd = new SayDelegate(SayHello); // the method SayHello is static method

            ad(20, 30);
            ad.Invoke(10, 10); // or we can use it like this
            str = sd("Karren");
            Console.WriteLine(str);
            Console.ReadLine();
        }
Exemple #19
0
        static void Main(string[] args)
        {
            Delegates p = new Delegates();
            //Step 2: Instantiating a delegate
            AddDelegate ad = new AddDelegate(p.AddNums);

            //Step 3: Calling a delegate
            ad.Invoke(100, 50);
            //ad(100, 50); -- Optional way to call delegate
            //Step 2: Instantiating a delegate
            SayDelegate sd = new SayDelegate(Delegates.SayHello);
            //Step 3: Calling a delegate
            string str = sd.Invoke("Manish");

            // string str = sd("Manish");

            //p.AddNums(100, 50);
            //string str = Delegates.SayHello("Manish");
            Console.WriteLine(str);
            Console.ReadLine();
        }
        /// <summary>
        /// Instantiating and Invoking Delegate
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            ClsDelegatedemo3 obj  = new ClsDelegatedemo3();
            AddDelegate      obj1 = new AddDelegate(obj.Add);

            obj1.Invoke(26.3, 48.9);

            SubDelegate obj2 = new SubDelegate(obj.Sub);

            obj2.Invoke(32, 47);

            checkLengthDelegate obj3 = new checkLengthDelegate(obj.CheckLength);
            bool status = obj3.Invoke("false");

            log.Info(status);
            CalLengthDelegate obj4 = new CalLengthDelegate(obj.CalLength);
            bool status1           = obj4.Invoke("true");

            log.Info(status1);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Program p = new Program();

            // create instance of delegates
            AddDelegate ad = new AddDelegate(Program.Add);
            AddName     an = new AddName(p.Name);
            AddJob      aj = new AddJob(Program.Job);// normal call also applicable , keeping Class Name by calling is optional

            // in case of static methods

            // now call the delegate , by pass the value so that the method which is bound with delegate internally should execute
            ad(100, 200);
            ad.Invoke(2000, 20200);
            an.Invoke("laxman");
            an("shukla");
            string s1 = aj("ved");
            string s  = aj.Invoke("praksh");

            Console.WriteLine(s1);
            Console.WriteLine(s);
            Console.WriteLine("Complete");
            Console.Read();
        }
Exemple #22
0
        static void Main(string[] args)
        {
            //Single cast Delegate explanation//
            Console.BackgroundColor = ConsoleColor.Cyan;
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("******Single Cast with Basic Explanation********");
            Console.ResetColor();
            SingleCastDelegate sobj = new SingleCastDelegate();
            AddDelegate        ad   = sobj.Add;

            ad.Invoke(100, 100);
            GreetingsMessage gd = new GreetingsMessage(SingleCastDelegate.Greetings);
            // GreetingsMessage gd = new GreetingsMessage(SingleCastDelegate.Greetings);
            string name = gd.Invoke("Limon");

            Console.WriteLine(name);

            //Multicast Basic explanation//
            Console.BackgroundColor = ConsoleColor.Cyan;
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("******Multicast with Basic Explanation********");
            Console.ResetColor();
            Multicast    obj    = new Multicast();
            MathDelegate md     = Multicast.Add;
            MathDelegate mdSub  = Multicast.Sub;
            MathDelegate mdMul  = obj.Mul;
            MathDelegate mdDiv  = obj.Div;
            MathDelegate mainMd = md + mdSub + mdMul + mdDiv;

            mainMd.Invoke(10, 10);
            mainMd -= mdSub;
            Console.WriteLine($"After removing {mdSub}");
            mainMd.Invoke(20, 50);

            //Multicast with return type//
            Console.BackgroundColor = ConsoleColor.Cyan;
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("******Multicast with return type********");
            Console.ResetColor();
            // ReturnType rt = new ReturnType();
            ReturnDelegate rd = ReturnType.Method1;

            rd += ReturnType.Method2;
            int valueGet = rd();

            Console.WriteLine("Return Value:{0}", valueGet);

            Console.BackgroundColor = ConsoleColor.Cyan;
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("******Multicast with Out type********");
            Console.ResetColor();

            ReturnDelegateOUt rdo = ReturnType.OutMethod1;

            rdo += ReturnType.OutMethod2;
            int    IdFromOut       = -1;
            string UserNameFromOut = null;

            rdo(out IdFromOut, out UserNameFromOut);
            Console.WriteLine($"Value from Output parameter Id: {IdFromOut} Name:{UserNameFromOut}");

            //
            Console.BackgroundColor = ConsoleColor.Cyan;
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("******Multicast with RealLife example********");
            Console.ResetColor();
            Employee emp1 = new Employee()
            {
                ID         = 101,
                Name       = "Pranaya",
                Gender     = "Male",
                Experience = 5,
                Salary     = 10000
            };
            Employee emp2 = new Employee()
            {
                ID         = 102,
                Name       = "Priyanka",
                Gender     = "Female",
                Experience = 10,
                Salary     = 20000
            };
            Employee emp3 = new Employee()
            {
                ID         = 103,
                Name       = "Anurag",
                Experience = 15,
                Salary     = 30000
            };
            List <Employee> listEmployess = new List <Employee>()
            {
                emp1, emp2, emp3
            };

            // EligibleToPromotion eligbleDelegate = Employee.Promote;

            //Employee.PromoteEmployee(listEmployess, eligbleDelegate);
            Employee.PromoteEmployee(listEmployess, x => x.Salary >= 10000);
        }
Exemple #23
0
        static void Main(string[] args)
        {
            List <int> numbers = new List <int>()
            {
                1, 3, 5, 7, 8, 9, 11, 13, 14, 15
            };

            IEnumerable <int> largeNumber = numbers.Where(c => c > 14);

            foreach (int i in largeNumber)
            {
                Console.WriteLine("Large Number is " + i);
            }

            IEnumerable <int> results = from num in numbers
                                        where num < 3 || num > 7
                                        orderby num descending
                                        select num;

            int count =                 /*(from num in numbers
                                        *  where num < 3 || num > 7
                                        *  orderby num descending
                                        *  select num).Count();*/

                        numbers.Where(n => n < 3 || n > 10).Count();

            Console.WriteLine("Count is " + count);

            foreach (int num in results)
            {
                Console.WriteLine("number is : " + num);
            }

            string[] groupingQuery = { "carrots", "cabbage", "broccoli", "beans", "barley" };
            IEnumerable <IGrouping <char, string> > gQuery =
                from item in  groupingQuery
                group item by item[0];

            foreach (var item in gQuery)
            {
                //Console.WriteLine("Grouped Items are  - ");
            }
            Student.QueryHighScores(1, 90);
            Console.WriteLine("Hello World!");

            MQ app = new MQ();

            int[] nums = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            var q1 = app.QueryMethod1(ref nums);

            foreach (string s in q1)
            {
                Console.WriteLine("string is - " + s);
            }

            IEnumerable <string> mq2;

            app.QueryMethod2(ref nums, out mq2);

            foreach (string s in mq2)
            {
                Console.WriteLine(s);
            }

            Student.GroupBySingleProperty();

            FileLogger file = new FileLogger("/Users/giridharreddykatha/Documents/Logs/log.txt");

            Logger.LogMessage(Severity.Error, "This is Error", "This Error is caused");

            Logger.LogMessage(Severity.Critical, "This is Critical Error", "Big  Error");


            AddDelegate ad = new AddDelegate(DelegateDemo.Add);

            ad.Invoke(10, 20);


            MulDelegate md = MulticastDelegate.Area;

            md += MulticastDelegate.Circumference;

            md.Invoke(10.2, 12);

            GreetingDelegate gd = delegate(string name)
            {
                return("Hello " + name + " A Very Good Morning!!");
            };

            Console.WriteLine(gd.Invoke("Friend"));

            GreetingDelegate g = (name) => { return("Hello " + name + " A Very Good Morning!!"); };

            Console.WriteLine(g.Invoke("Mike"));

            Console.ReadLine();
        }