27
1
using System;
2
3
delegate void ArDelegate(int a, int b);
4
5
public class ArithematicOperation {
6
public static void Add(int a, int b) {
7
Console.WriteLine("{0} + {1} = {2}", a, b, a + b);
8
}
9
public static void Sub(int a, int b) {
10
Console.WriteLine("{0} - {1} = {2}", a, b, a - b);
11
}
12
}
13
14
public class DelegateProgram {
15
16
public static void Main() {
17
ArDelegate del = new ArDelegate(ArithematicOperation.Add);
18
//multicast delegate here
19
del += new ArDelegate(ArithematicOperation.Sub);
20
del(4, 2);
21
22
del -= new ArDelegate(ArithematicOperation.Sub);
23
del(1, 9);
24
25
}
26
27
}
Cached Result