Calling functions through Delegates
Description
Here is the code snippet demonstrate that how to call multiple member functions through Multicast Delegates.
class A
{
//Declared the Multicast Delegate(Void Return type)
public delegate void MyDelegate(int a,int b);
public static void Main(string[] args)
{
B b = new B();
MyDelegate Handler;
Handler = new MyDelegate(b.Add); //Added address of first function.
Handler += new MyDelegate(b.Subtract); //Added address of first function.
Handler(3, 4); //Calling functions.
Console.ReadLine();
}
}
class B
{
public void Add(int a, int b)
{
Console.WriteLine("Sum is:{0}",a + b);
}
public void Subtract(int a, int b)
{
Console.WriteLine("Difference is:{0}", Math.Abs(a - b));
}
}
