1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace @delegate
7{
8 class MultiDelegateExam
9 {
10 delegate void Dialoging();
11 public static void Greeting()
12 {
13 Console .WriteLine ("How are you !");
14 }
15 public static void Introduce()
16 {
17 Console .WriteLine ("I am Norosin.");
18 }
19 public static void Main(string[] args)
20 {
21 Dialoging oneDialoging = new Dialoging(Greeting);
22 Console.WriteLine("single delegate:one");
23 oneDialoging();
24 Console.WriteLine();
25
26 Dialoging twoDialoging = new Dialoging(Introduce);
27 Console.WriteLine("single delegate:two");
28 twoDialoging();
29 Console.WriteLine();
30
31 Dialoging threeDialoging = oneDialoging + twoDialoging;
32 Console.WriteLine("multicast delegate:one+two");
33 threeDialoging();
34 Console.WriteLine();
35
36 Dialoging fourDialoging = threeDialoging - twoDialoging;
37 Console.WriteLine("single delegate:three-two");
38 fourDialoging();
39 Console.WriteLine();
40
41 Console.WriteLine("按Enter键退出");
42 Console.Read();
43 }
44 }
45}
46
47
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace @delegate
7{
8 class MultiDelegateExam
9 {
10 delegate void Dialoging();
11 public static void Greeting()
12 {
13 Console .WriteLine ("How are you !");
14 }
15 public static void Introduce()
16 {
17 Console .WriteLine ("I am Norosin.");
18 }
19 public static void Main(string[] args)
20 {
21 Dialoging oneDialoging = new Dialoging(Greeting);
22 Console.WriteLine("single delegate:one");
23 oneDialoging();
24 Console.WriteLine();
25
26 Dialoging twoDialoging = new Dialoging(Introduce);
27 Console.WriteLine("single delegate:two");
28 twoDialoging();
29 Console.WriteLine();
30
31 Dialoging threeDialoging = oneDialoging + twoDialoging;
32 Console.WriteLine("multicast delegate:one+two");
33 threeDialoging();
34 Console.WriteLine();
35
36 Dialoging fourDialoging = threeDialoging - twoDialoging;
37 Console.WriteLine("single delegate:three-two");
38 fourDialoging();
39 Console.WriteLine();
40
41 Console.WriteLine("按Enter键退出");
42 Console.Read();
43 }
44 }
45}
46
47
运行结果: