//Below Example Defines MultiDelegateToMethod which holds reference to below three methods
void Add(int num1, int num2)
void Multiply(int num1, int num2)
void Divide(int num1, int num2)
//Invoke MultiDelegateToMethod to call all three methods one by one
void Add(int num1, int num2)
void Multiply(int num1, int num2)
void Divide(int num1, int num2)
//Invoke MultiDelegateToMethod to call all three methods one by one
using System;
namespace MultiCastDelegates
{
public delegate void MultiDelegateToMethod(int x, int y);
public class Math
{
public static void Add(int num1, int num2)
{
Console.WriteLine("Addition Is {0} ", num1 + num2);
}
public static void Multiply(int num1, int num2)
{
Console.WriteLine("Multiplication Is {0} ", num1 * num2);
}
public static void Divide(int num1, int num2)
{
Console.WriteLine("Division Is {0} ", num1 / num2);
}
}
public class DelegateApp
{
public static void Main()
{
MultiDelegateToMethod aDelegate = new MultiDelegateToMethod(Math.Add);
aDelegate = aDelegate + new MultiDelegateToMethod(Math.Multiply);
aDelegate = aDelegate + new MultiDelegateToMethod(Math.Divide);
//Invoke Add,Multiply ,Divide by just invoking aDelegate
aDelegate(10, 5);
}
}
}
Below is the o/p
No comments:
Post a Comment