Search This Blog

Wednesday, October 23, 2013

Mulicast delegate in C#

C# > Delegate

Mulicast delegate is a delegate that can have more than one element in its invocation list.

Example

public delegate void MultiDelegate(int x,int y);
private class Operator
{
            public void Add(int x, int y)
       {
              MessageBox.Show ("The sum is: " + (x + y));
       }
       public void Sub(int x, int y)
       {
              MessageBox.Show("The sub is: " + (x - y));
       }
}

MultiDelegate ptr=null;
//add more than one function called multicast delegate.
ptr += new MultiDelegate(obj.Add);
ptr += new MultiDelegate(obj.Sub);
ptr(50, 10);

<< Delegates                                                                                  Anonymous functions >>