4 + 2 = 6 4 - 2 = 2 1 + 9 = 10
This is a C# Program to implement multicast delegates.
This C# Program Implements Multicast Delegates.
Here Multicast delegate is a delegate which holds a reference to more than one method.
Here is source code of the C# Program to Implement Multicast Delegates. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.
/* * C# Program to Implement Multicast Delegates */ using System; delegate void dele(int a, int b); public class Oper { public static void Add(int a, int b) { Console.WriteLine("{0} + {1} = {2}", a, b, a + b); } public static void Sub(int a, int b) { Console.WriteLine("{0} - {1} = {2}", a, b, a - b); } } public class program { static void Main() { dele del = new dele(Oper.Add); del += new dele(Oper.Sub); del(4, 2); del -= new dele(Oper.Sub); del(1, 9); Console.Read(); } }
This C# program is used to implement multicast delegates. Using Add and Sub two methods perform addition and subtraction. The Multicast delegate is a delegate which holds a reference to more than one method. Using the delegate object variable ‘del’ we are calling the methods by passing the value as argument.
4 + 2 = 6 4 - 2 = 2 1 + 9 = 10