基于泛型的事件处理演示与净值2005
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于泛型的事件处理演示与净值2005相关的知识,希望对你有一定的参考价值。
Annotated version of the Microsoft/GotDotNet demo from the MSDN Wiki.
//Define a custom EventArgs class to contain your data. public class MyEventArgs : EventArgs { public string info = "data"; } //Declare the event as visible to users of the class public event EventHandler<MyEventArgs> MyEvent; //Send the event, note that this will throw a nullref if there are no subscribers //Internal version prevents outsiders from needing to know about the contents of MyEventArgs protected virtual void InternalSendMyEvent(CustomEventArgs e) { if(MyEvent != null) { e.info = "Hello Events!"; //This calls all registered subscribers with the following parameters. MyEvent(this, e); } } //Public version to allow outsiders to trigger the event, not typical implementation. public void CreateEvent() { } //Consumer //Register the Handler //Define the Handler private void HandleEvent(object sender, MyEventArgs e) { MessageBox.Show("Event handled:" + e.info); } //Cause the Event eventRaiser.CreateEvent();
以上是关于基于泛型的事件处理演示与净值2005的主要内容,如果未能解决你的问题,请参考以下文章