|
Answer» If a Delegate invokes MULTIPLE METHODS, these are called Multicast Delegates.
Let us see an example: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
delegate VOID DemoDelegate();
CLASS Example
{
static public void One()
{
Console.WriteLine("One");
}
static public void Two()
{
Console.WriteLine("Two");
}
static public void Three()
{
Console.WriteLine("Three");
}
}
class DEMO
{
public static void Main()
{
DemoDelegate d1 = new DemoDelegate(Example.One);
DemoDelegate d2 = new DemoDelegate(Example.Two);
DemoDelegate d3 = new DemoDelegate(Example.Three);
DemoDelegate d4 = d1 + d2 + d3;
DemoDelegate d5 = d2 + d3 + d4;
DemoDelegate d6 = d3 - d4 + d5;
d3();
d4();
d5();
d6();
}
}The output: Three
One
Two
Three
Two
Three
One
Two
Three
Two
Three
One
Two
Three
|