static void Main(string[] args) { SampleDelegate SD1, SD2, SD3, SD4; SD1 = new SampleDelegate(SampleMethod1); SD2 = new SampleDelegate(SampleMethod2); SD3 = SD1 + SD2; SD3(); //This is a multicast delegate SD4 = SD1 + SD2 - SD1; //like the + sign , - sign can also be used to remove the delegates (here , SD4 = SD2 basically) SD4(); SampleDelegate SD5 = new SampleDelegate(SampleMethod1); SD5 += SampleMethod2; //Another way to multicast delegates SD5(); //Here , we don't need to create many instances of the delegate to make it multicast Console.ReadKey(); ReturningValueDelegate RVD; //Demonstrating return value RVD = new ReturningValueDelegate(ReturningValueMethod1); RVD += ReturningValueMethod2; int ReturnedValue = RVD(); Console.WriteLine("Returned Value is {0}", ReturnedValue); Console.ReadKey(); OutputParameterDelegate OPD; //Demonstrating output parameter OPD = new OutputParameterDelegate(OutputParameterMethod1); OPD += OutputParameterMethod2; int OutParameter = -1; OPD(out OutParameter); Console.WriteLine("Final output parameter is {0}", OutParameter); Console.ReadKey(); }
static void Main(string[] args) { SampleDelegate SD1, SD2, SD3,SD4; SD1 = new SampleDelegate(SampleMethod1); SD2 = new SampleDelegate(SampleMethod2); SD3 = SD1 + SD2; SD3(); //This is a multicast delegate SD4 = SD1 + SD2 - SD1;//like the + sign , - sign can also be used to remove the delegates (here , SD4 = SD2 basically) SD4(); SampleDelegate SD5 = new SampleDelegate(SampleMethod1); SD5 += SampleMethod2; //Another way to multicast delegates SD5();//Here , we don't need to create many instances of the delegate to make it multicast Console.ReadKey(); ReturningValueDelegate RVD;//Demonstrating return value RVD = new ReturningValueDelegate(ReturningValueMethod1); RVD += ReturningValueMethod2; int ReturnedValue = RVD(); Console.WriteLine("Returned Value is {0}", ReturnedValue); Console.ReadKey(); OutputParameterDelegate OPD; //Demonstrating output parameter OPD = new OutputParameterDelegate(OutputParameterMethod1); OPD += OutputParameterMethod2; int OutParameter = -1; OPD(out OutParameter); Console.WriteLine("Final output parameter is {0}", OutParameter); Console.ReadKey(); }