兩個類之間互動
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 }