标签:
1 code
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace ConsoleApplication3 8 { 9 class Test 10 { 11 //EventHandler在winform中用的多 12 //与它匹配的方法,必须具备object与eventargs两个参数 13 public event EventHandler MyEventHandler; 14 15 public void A(object o,EventArgs e) 16 { 17 MyEventHandler(o, e); 18 } 19 } 20 class Program 21 { 22 static void Main(string[] args) 23 { 24 25 Test a = new Test(); 26 a.MyEventHandler += test; 27 28 //这样写是错误的,事件不可以在其他类中调用 29 //a.MyEventHandler(); 30 a.A(new object(), new EventArgs()); 31 32 33 Console.ReadKey(); 34 } 35 36 37 public static void test(object o, EventArgs e) 38 { 39 Console.WriteLine("OK"); 40 } 41 } 42 43 }
2 show
3 扩展
标签:
原文地址:http://www.cnblogs.com/jinlingzi/p/5978931.html