public static void Main()
        {
            Program p = new Program();

            addnum ad = new addnum(p.add);
            int    a  = ad(10, 20); //ad.Invoke(10,20)
            //Console.WriteLine(a);


            subnum sb = new subnum(p.sub);

            // Console.WriteLine(  sb(10,20));


            calculator c   = new calculator(p.add);
            int        ans = c.Invoke(12, 23);

            Console.WriteLine(ans);
            c = c + p.sub;
            int ans2 = c.Invoke(1, 1);

            Console.WriteLine(ans2);

            //multicast delegate
            rectDelegate rd = new rectDelegate(p.area);

            rd += p.perimeter;
            rd.Invoke(10, 4);
        }
Example #2
0
        public void Execute()
        {
            // creating object "obj" of class "Geeks"
            Delegates _DelegatesTest = new Delegates();

            // creating object of delegate, name as "del_obj1"
            // for method "sum" and "del_obj2" for method "subtract" &
            // pass the parameter as the two methods by class object "obj"
            // instantiating the delegates
            addnum del_obj1 = new addnum(_DelegatesTest.Summation);
            subnum del_obj2 = new subnum(_DelegatesTest.Subtraction);

            //div del_obj3 = new div(_DelegatesTest.Subtraction);
            // pass the values to the methods by delegate object
            del_obj1(100, 40);
            del_obj2(100, 60);
            //del_obj3(100, 50);

            //float abc = del_obj3(100, 50);

            // These can be written as using
            // "Invoke" method
            // del_obj1.Invoke(100, 40);
            // del_obj2.Invoke(100, 60);
        }
Example #3
0
        public void DelegateExample()
        {
            // creating object "obj" of class "Geeks"
            Delegate2 obj = new Delegate2();

            // creating object of delegate, name as "del_obj1"
            // for method "sum" and "del_obj2" for method "subtract" &
            // pass the parameter as the two methods by class object "obj"
            // instantiating the delegates
            addnum del_obj1 = new addnum(obj.sum);
            subnum del_obj2 = new subnum(obj.subtract);

            //Multicast delegates
            del_obj1 += obj.subtract;


            // pass the values to the methods by delegate object
            del_obj1(100, 40);
            del_obj2(100, 60);

            // These can be written as using
            // "Invoke" method
            // del_obj1.Invoke(100, 40);
            // del_obj2.Invoke(100, 60);
        }
        public static void Main()
        {
            Delegate_Demo2 del2     = new Delegate_Demo2();
            addnum         del_obj1 = new addnum(del2.sum);
            subnum         del_obj2 = new subnum(del2.subtract);

            del_obj1(100, 40);
            del_obj2(100, 60);
        }
Example #5
0
        static void Main(string[] args)
        {
            Program obj      = new Program();
            addnum  del_obj1 = new addnum(obj.sum);
            subnum  del_obj2 = new subnum(obj.subtract);

            del_obj1(100, 40);
            del_obj2(100, 60);
        }
        public static void Main(String [] args)
        {
            Geeks obj = new Geeks();


            addnum del_obj1 = new addnum(obj.sum);
            subnum del_obj2 = new subnum(obj.subtract);

            del_obj1(100, 40);
            del_obj2(100, 60);
        }
    public static void Main(string [] args)
    {
        Delegates obj      = new Delegates();
        addnum    del_obj1 = new addnum(obj.sum);
        subnum    del_obj2 = new subnum(obj.subtract);

        del_obj1(100, 40);      // Calling of Delegates
        //del_obj1.Invoke(100,40)

        del_obj2(100, 60);
        //del_obj2.Invoke(100,40)
    }
Example #8
0
    public static void Main(String[] args)
    {
        var obj = new del();


        addnum del_obj1 = new addnum(obj.sum);
        subnum del_obj2 = new subnum(obj.subtract);



        del_obj1.Invoke(51, 50);
        del_obj2.Invoke(51, 50);
    }
Example #9
0
        // Main Method
        public static void Main(String[] args)
        {
            // creating object "obj" of class "Geeks"
            Delegates obj      = new Delegates();
            addnum    del_obj1 = new addnum(obj.sum);
            subnum    del_obj2 = new subnum(obj.subtract);
            square    del_obj3 = new square(obj.area);

            del_obj1(100, 40);
            del_obj2(100, 60);
            del_obj3 += obj.perimeter;
            del_obj3.Invoke(3, 4);
            Console.WriteLine();
            Console.ReadKey();
        }
        public static void Main()
        {
            addnum ad = delegate(int a, int b){
                return(a + b);
            };

            Console.WriteLine(ad(1, 2));


            subnum sb = delegate(int a, int b){
                return(a - b);
            };

            Console.WriteLine(sb(10, 3));
        }
Example #11
0
        static void Main(string[] args)
        {
            Program obj = new Program();

            addnum del_obj1 = new addnum(obj.sum);
            subnum del_obj2 = new subnum(obj.substract);

            del_obj1(100, 40);
            del_obj2(100, 60);

            //del_obj1.Invoke(100, 40);
            //del_obj2.Invoke(100, 60);

            Console.ReadLine();
        }
Example #12
0
        static void Main(string[] args)
        {
            SomeClass d1 = new SomeClass();

            //For ssingle delegate
            // creating object of delegate, name as "del_obj1"
            addnum del_obj1 = new addnum(d1.AdditionFN);
            subnum del_obj2 = new subnum(d1.SubtractionFN);

            // pass the values to the methods by delegate object
            del_obj1(100, 40);
            del_obj2(100, 60);

            Console.ReadKey();

            Console.WriteLine();

            //For ssingle delegate



            // For MultiCasst Delegate

            // creating delegate object, name as "rectdele"
            // and pass the method as parameter by
            // class object "rect"
            rectDelegate rectdele = new rectDelegate(d1.area);

            //or
            // rectDelegate rectdele1 = d1.area;

            // call 2nd method "perimeter"
            // Multicasting

            rectdele += d1.perimeter;

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

            // call the methods with
            // different values
            rectdele.Invoke(16.3, 10.3);

            Console.ReadKey();
        }