简单事件
程序员文章站
2022-07-23 08:34:26
两个类之间交互 ......
两个类之间交互
1 using system; 2 3 namespace event 4 { 5 class program 6 { 7 static void main(string[] args) 8 { 9 var a = new a(); 10 program p = new program(); 11 a.events += p.message; 12 a.ziduana(); 13 console.readline(); 14 } 15 16 private void a_events(string a) 17 { 18 console.writeline(a); 19 } 20 21 public void message(string a) 22 { 23 console.writeline("事件"+a); 24 } 25 } 26 27 class a 28 { 29 public delegate void event(string a); 30 public event event events; 31 public void ziduana() 32 { 33 events("输入a"); 34 } 35 } 36 }