Such type’s delegates which hold and invoke multiple methods are known as multicast delegates. But simple delegates invoke only one method. Multicast delegates must satisfy the following condition:
· The return type of the delegate must void.
· None of the parameters of the delegate type can be declared as output parameters, using out keywords.
For Example:
delegate void Multidelegate();
class Program
{
public static void Main()
{
Multidelegate mshow1 = new Multidelegate(Class1.show1);
Multidelegate mshow2 = new Multidelegate(Class1.show2);
Multidelegate mshow3 = mshow1 - mshow2;
Multidelegate mshow4 = mshow2 - mshow1;
Multidelegate mshow5 = mshow3 - mshow2;
Multidelegate mshow6= mshow5 - mshow4;
mshow3();
mshow4();
mshow5();
mshow6();
Console.ReadLine();
}
}
class Class1
{
static public void show1()
{
Console.WriteLine("India");
}
static public void show2()
{
Console.WriteLine("England");
}
}
Output:
India
England
India
India
Leave Comment
2 Comments