Esempio n. 1
0
        static void Main()
        {
            Rectangle    rect = new Rectangle();
            RectDelegate obj  = new RectDelegate(rect.GetArea);

            obj += rect.GetPerimeter;
            obj.Invoke(56.23, 23.45);
            Console.WriteLine("\n");
            //Break line
            Console.WriteLine("Good Morning");

            Traingle     trai = new Traingle();
            traiDelegate obj1 = new traiDelegate(trai.TraiArea);

            obj1.Invoke(56.36, 58.56);
            Console.WriteLine("\n");
            Console.WriteLine("Good Morning");


            TestdelegateMethod p   = new TestdelegateMethod();
            DelMethod          del = new DelMethod(p.method_1);

            // Here we have multicast
            del += new DelMethod(p.method_2);
            Console.WriteLine(del(50, 10));

            // Here again we have multicast
            del -= new DelMethod(p.method_2);
            Console.WriteLine(del(20, 10));
            Console.ReadKey();
        }
Esempio n. 2
0
        static void Main1(string[] args)
        {
            MulticastDelegateDemo obj = new MulticastDelegateDemo();
            RectDelegate          del = obj.GetArea;

            del += obj.GetPerimeter;
            del.Invoke(2, 3);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            Delegates3   d  = new Delegates3();
            RectDelegate rd = new RectDelegate(d.GetArea);

            rd += d.GetPerimeter;
            rd.Invoke(20.2, 88.2);
            Console.Read();
        }
        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();
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Console.WriteLine("MultiCast Delegate");
            Rectangle    rect = new Rectangle();
            RectDelegate obj  = new RectDelegate(rect.Area);

            obj += rect.Perimeter;
            obj.Invoke(20, 10);
            Console.Read();
        }
        public void Main()
        {
            Rectangle    rectangle    = new Rectangle();
            RectDelegate rectDelegate = rectangle.GetArea;

            rectDelegate += rectangle.GetPerimeter;

            rectDelegate.Invoke(10, 20);
            Console.ReadKey();
        }
Esempio n. 7
0
        static void Main(string[] args)
        {
            ClsDelegate5 obj1 = new ClsDelegate5();
            RectDelegate obj2 = new RectDelegate(obj1.GetArea);

            obj2 += obj1.GetPerimeter;
            obj2(12.34, 56.78);
            Console.WriteLine();
            obj2(17.13, 45.87);
            Console.Read();
        }
Esempio n. 8
0
        static void Main(string[] args)
        {
            Rectangle    rect = new Rectangle();
            RectDelegate obj  = new RectDelegate(rect.GetArea);

            obj += rect.GetPerimeter;
            obj.Invoke(12.43, 56.78);
            Console.WriteLine();

            obj.Invoke(10.11, 12.12);
            Console.ReadLine();
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            RectClass    rc = new RectClass();
            RectDelegate rd = new RectDelegate(rc.GetArea);

            rd += rc.GetPerimeter;

            rd.Invoke(5, 4);
            // rc.GetArea(4,5);
            // rc.GetPerimeter(4,5);
            Console.WriteLine("Hello World!");
        }
Esempio n. 10
0
        static void Main()
        {
            //step2-- Instanting the delegate using anonymous method
            RectDelegate r1 = delegate(double width, double height)
            {
                return(width * height);
            };

            // step3 -- Invoking delegate
            Console.WriteLine("Area of Rectangle is :{0}", r1.Invoke(10.10, 20.20));
            Console.ReadKey();
        }
Esempio n. 11
0
        static void MultiCastDelegateDemo()
        {
            RectDelegate rd = new RectDelegate(Area);

            // Call 2nd method Perimeter.
            rd += Perimeter;

            // pass the values in two method by using "Invoke" method.
            rd.Invoke(6.3, 4.2);

            // call the methods with different values
            rd.Invoke(16.3, 10.3);
        }
        public static void Main(String[] args)
        {
            // The object 'rect' is instantiated using the default
            // constructor
            Rectangle rect = new Rectangle();

            // The delegate is called and passes the parameters
            // to the Area() method
            RectDelegate rectdele = new RectDelegate(rect.Area);

            // The delegate is called again and passes the parameters
            // to the Perimeter() method using a different syntax
            rectdele += rect.Perimeter;

            // Added user input to program to calculate multiple shapes
            // using an array to store the values of each shape

            Console.WriteLine("-----------------------------------------------------------");
            Console.WriteLine("Program to Calculate the Area and Perimeter for Rectangles");
            Console.WriteLine("-----------------------------------------------------------\n");

            Console.WriteLine("How many shapes are you calculating?");
            int n = Convert.ToInt32(Console.ReadLine());

            double[] shapes = new double[n];

            // The foreach loop iterates through the array and saves
            // the value for each shape sequentially
            foreach (double shape in shapes)
            {
                Console.WriteLine("\nEnter the height of the rectangle : ");
                string _valueOne = (Console.ReadLine());
                if (Double.TryParse(_valueOne, out double ValueOne))
                {
                    ;
                }

                Console.WriteLine("\nEnter the width of the rectangle : ");
                string _valueTwo = (Console.ReadLine());
                if (Double.TryParse(_valueTwo, out double ValueTwo))
                {
                    ;
                }

                // Finally, the delegate is invoked for each shape
                // prints the results passed from the methods back
                // to the user
                rectdele.Invoke(ValueOne, ValueTwo);
                Console.WriteLine();
            }
        }
Esempio n. 13
0
        static void Main()
        {
            MultiCastDelegate rect = new MultiCastDelegate();
            //RectDelegate obj = new RectDelegate(rect.GetArea);
            RectDelegate obj = rect.GetArea;//optional way to declare delegate without Constructor.

            obj += rect.GetPerimeter;
            obj.Invoke(12.34, 56.78);
            Console.WriteLine();
            obj.Invoke(47.87, 34.89);
            //rect.GetArea(12.34, 56.78);
            //rect.GetPerimeter(12.34, 56.78);
            Console.ReadLine();
        }
Esempio n. 14
0
        static void Main()
        {
            Multipledelegater m = new Multipledelegater();
            //m.GetArea(1.0,2.0);
            //m.GetPerimeter(12.3,52.3);

            RectDelegate r = m.GetArea; //4127

            r += m.GetPerimeter;        //we can perform bindg one sigle delegate call both call output
            r.Invoke(12.34, 334.5);
            Console.WriteLine();
            r.Invoke(142.34, 3434.5); // RectDelegate this delegate holding referce of two methods and both method bound of and make it as a single call
            Console.ReadLine();
        }
        static void Main()
        {
            Program      rect = new Program();
            RectDelegate obj  = rect.GetArea;

            //obj.Invoke(34, 45);
            obj += rect.GetPerimeter;
            obj.Invoke(12, 10);
            obj.Invoke(12, 12);

            //rect.GetArea(12.34, 56.78);
            //rect.GetPerimeter(12.34, 56.78);
            Console.ReadLine();
        }
Esempio n. 16
0
        static void Main(string[] args)
        {
            Rectangle rect = new Rectangle();

            RectDelegate obj = new RectDelegate(rect.GetArea); //Instantiating of the delegate

            obj += rect.GetPerimeter;                          //Multicast Delegate

            obj.Invoke(12.34, 56.78);                          //Parameter passing

            Console.WriteLine();
            obj.Invoke(47.87, 34.89);// other rectangles properties also can be obtained by single call of delegate

            Console.ReadKey();
        }
Esempio n. 17
0
        static void Main(string[] args)
        {
            Rectangle rt = new Rectangle();

            // RectDelegate obj = new RectDelegate(rt.GetArea);
            RectDelegate obj1 = rt.GetArea;

            obj1 += rt.GetPerimeter;//holding reference of two method
            obj1.Invoke(12.34, 56.78);
            //rt.GetArea(12.3 , 23.4);
            //rt.GetPerimeter(23.4 , 56.7);
            Console.WriteLine();
            obj1.Invoke(23.45, 56.78);
            Console.ReadLine();
        }
        static void Main(string[] args)
        {
            Ractangle    rect = new Ractangle();
            RectDelegate obj  = rect.GetArea;

            obj += rect.GetPerimeter;
            obj.Invoke(12.34, 56.78);

            RectDelegate1 ob = rect.GetArea1;

            ob += rect.GetPerimeter1;

            Console.WriteLine(ob.Invoke(12.34, 56.78));

            //rect.GetArea(12.34, 56.78);
            //rect.getPerimeter(12.34, 56.78);

            Console.ReadKey();
        }
Esempio n. 19
0
        static void Main(string[] args)
        {
            Program rect = new Program();

            //2. Create an instance
            RectDelegate myrect = new RectDelegate(rect.GetArea);

            myrect += rect.GetPerimeter;



            rect.GetArea(11.3, 12.0);
            rect.GetPerimeter(11.3, 12.0);

            Console.WriteLine("I am going to execute a delegate");
            myrect.Invoke(11.3, 12.0);

            Console.ReadLine();
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            log4net.Config.BasicConfigurator.Configure();

            Rectangle rectangle = new Rectangle();

            log.Info("Area of Rectangle :: " + rectangle.GetArea(12.34, 56.78));
            log.Info("Perimeter of the Rectangle :: " + rectangle.GetPerimeter(12.34, 56.78));

            log.Info("Getting area and perimeter using delegates");
            RectDelegate rectDelegate = rectangle.GetArea;

            rectDelegate += rectangle.GetPerimeter;

            //This will be calling both the methods and execute both the methods, but the proble is..it will be showing last methods result because 1st method's result is being overwritten by last method.
            log.Info("Area and Perimeter using Delegate :: " + rectDelegate.Invoke(12.34, 56.78));

            //This is anonymous method delclaration using delegate.
            Greetings greetings = delegate(string Name)
            {
                return("Hello " + Name);
            };

            log.Info(greetings.Invoke("Ramesh"));

            //Lambda Expression using delegate
            greetings = (Name) =>
            {
                return("Hello " + Name + ",  have a nice day !!!");
            };
            log.Info(greetings.Invoke("Ramesh Khanna"));

            //Lambda method call
            List <int> list = rectangle.LambdaMethod();

            foreach (int number in list)
            {
                log.Info(number);
            }

            Console.Read();
        }