Delegate
Wed Oct 29 2025 17:17:26 GMT+0000 (Coordinated Universal Time)
Saved by
@vplab
namespace DelegateDemo
{
delegate void Operation(int a,int b);
class Program
{
static void Add(int a,int b)
{
Console.WriteLine("Add:"+(a+b));
}
static void Sub(int a, int b)
{
Console.WriteLine("Sub:" + (a - b));
}
static void Mul(int a, int b)
{
Console.WriteLine("Mul:" + (a + b));
}
static void Mod(int a, int b)
{
Console.WriteLine("Mod:" + (a % b));
}
public static void Main(string[] args)
{
Operation opAdd= Add;
Operation opSub = Sub;
Operation opMul = Mul;
Operation opMod = Mod;
opAdd(5,6);
opSub(5, 6);
opMul(5, 6);
opMod(5, 6);
Console.WriteLine("Multicast Delegate:");
Operation mul= opAdd + opSub + opMul + opMod;
mul(10, 3);
}
}
}
content_copyCOPY
Comments