class
1using System;
2using System.Collections.Generic;
3
4namespace ConsoleApplication3
5{
6 /**//// <summary>
7 /// 事件接受类
8 /// </summary>
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 EventSend es = new EventSend();
14 es.myEvent+=new EventSend.myDelegate(es_myEvent);
15 es.Run();
16 }
17
18 private static void es_myEvent(object sender,MyEventArgs e)
19 {
20 //事件处理方法
21 Console.WriteLine("\n你触发了一次事件!\n你输入的是:"+ e.InputText);
22 }
23 }
24 /**//// <summary>
25 /// 事件发送类
26 /// </summary>
27 class EventSend
28 {
29 public delegate void myDelegate(object sender, MyEventArgs e);//定义委托
30 public event myDelegate myEvent;//定义委托类型的事件
31 public void Run()
32 {
33 while (true)
34 {
35 Console.BackgroundColor = ConsoleColor.Red;
36 Console.ForegroundColor = ConsoleColor.Yellow;
37 Console.WriteLine("=== 退出请选择 n 或 N ===");
38 MyEventArgs e1 = new MyEventArgs();
39 e1.InputText = Console.ReadLine();
40 string str = e1.InputText;
41 if (str == "n" || str == "N")
42 {
43 break;
44 }
45 myEvent(this, e1);
46 }
47 }
48 }
49
50 /**//// <summary>
51 /// 事件的内容
52 /// </summary>
53 class MyEventArgs:EventArgs
54 {
55 private string inputText;
56 public string InputText
57 {
58 get
59 {
60 return this.inputText;
61 }
62 set
63 {
64 this.inputText = value;
65 }
66 }
67 }
68}
69
1using System;
2using System.Collections.Generic;
3
4namespace ConsoleApplication3
5{
6 /**//// <summary>
7 /// 事件接受类
8 /// </summary>
9 class Program
10 {
11 static void Main(string[] args)
12 {
13 EventSend es = new EventSend();
14 es.myEvent+=new EventSend.myDelegate(es_myEvent);
15 es.Run();
16 }
17
18 private static void es_myEvent(object sender,MyEventArgs e)
19 {
20 //事件处理方法
21 Console.WriteLine("\n你触发了一次事件!\n你输入的是:"+ e.InputText);
22 }
23 }
24 /**//// <summary>
25 /// 事件发送类
26 /// </summary>
27 class EventSend
28 {
29 public delegate void myDelegate(object sender, MyEventArgs e);//定义委托
30 public event myDelegate myEvent;//定义委托类型的事件
31 public void Run()
32 {
33 while (true)
34 {
35 Console.BackgroundColor = ConsoleColor.Red;
36 Console.ForegroundColor = ConsoleColor.Yellow;
37 Console.WriteLine("=== 退出请选择 n 或 N ===");
38 MyEventArgs e1 = new MyEventArgs();
39 e1.InputText = Console.ReadLine();
40 string str = e1.InputText;
41 if (str == "n" || str == "N")
42 {
43 break;
44 }
45 myEvent(this, e1);
46 }
47 }
48 }
49
50 /**//// <summary>
51 /// 事件的内容
52 /// </summary>
53 class MyEventArgs:EventArgs
54 {
55 private string inputText;
56 public string InputText
57 {
58 get
59 {
60 return this.inputText;
61 }
62 set
63 {
64 this.inputText = value;
65 }
66 }
67 }
68}
69