具体方法:
-
定义事件
- 委托定义: public delegate void EventFountion(Param param);
- 事件定义: public event EventFountion eventFountion;
- 调用事件: if (eventFountion!= null) eventFountion(this.param);
-
使用事件
- 事件触发后的方法 public void a_eventFountion(Param param){ ... }
- 注册事件 ClassA a=new ClassA(); a.eventFountion+=new ClassA.EventFountion(a_eventFountion);
实例代码:
- 自定义事件 class ClassA{ //委托定义: public delegate void EventFountion(Param param); //事件定义: public event EventFountion eventFountion; //调用事件: public void init(){ if (eventFountion!= null) eventFountion(this.param); ... } ... }
- 注册事件 class ClassB{ //调用事件: public void fountion(){ ClassA a=new ClassA(); a.eventFountion+=new ClassA.EventFountion(a_eventFountion); } public void a_eventFountion(Param param){ .... } ... }