Saturday, December 6, 2014

Program To implement multi-cast delegates

7:28 PM - By azeheruddin khan 0

Description: - A delegate which refers to multiple methods during runtime is called as Multi-cast delegate which is derived from System.MulticastDelegate class. A multi-cast delegate can call multiple methods in a serial order. As all the methods of the multi-cast delegate are executed in a serial order, they should not return any value, if they are returning values then each method has to wait till its previous method has returned a value.  Thus, delegates are used to call multiple methods for an event at run time.

Example:


using System;

namespace MultiCastDelegate
{
    class Program
    {
        delegate void operate(int x, int y);
        static void Main(string[] args)
        {
            Operation o = new Operation();
            operate p = new operate(o.sum);
            p += o.difference;
            p += o.product;
            p(80, 90);
            Console.WriteLine();
            p -= o.product;
            p(80, 90);
            Console.ReadLine();

        }
    }

    public class Operation
    {
        int c;
        public void sum(int a, int b)
        {
            c = a + b;
            Console.WriteLine("the sum is " + c);
        }
        public void difference(int a, int b)
        {
            c = a - b;
            Console.WriteLine("the difference is " + c);
        }
        public void product(int a, int b)
        {
            c = a * b;
            Console.WriteLine("the product is " + c);
        }
    }

}


Output:




About the Author

I am Azeheruddin Khan having more than 6 year experience in c#, Asp.net and ms sql.My work comprise of medium and enterprise level projects using asp.net and other Microsoft .net technologies. Please feel free to contact me for any queries via posting comments on my blog,i will try to reply as early as possible. Follow me @fresher2programmer
View all posts by admin →

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

adsense

© 2014 Fresher2Programmer. WP Theme-junkie converted by Bloggertheme9
Powered by Blogger.
back to top