然后再介绍一下关于 EventArgs< T> ,这基本上不需要委托声明:
public EventHandler< SomeEventArgs>事件与(我想)相同的是/ b
private delegate Something(object o,SomeEventArgs e); 公共事件事件事件;使用 EventHandler ?我可以看到为什么发送对象可能是有用的,但并不是所有的时间 - 而且很多时候,EventArgs可能会变得烦人的处理。 >
解决方案Microsoft已经推出了一些使C#工作愉快的好方式。话虽如此,我建议你写你的事件处理程序,以方便你的客户端代码,而不是写很多代码,只是为了满足一个模式。
delegate void ClientMessageHandler(IClient client,IMessage message);
Reading my C# book, it talks about using events/delegates (I am assuming I am right in thinking an event is the equivalent of a public delegate which has no member variable access) in a pattern liked by MS:
public delegate Something(object o, EventArgs e)And then goes onto explain about EventArgs<T> which basically removes the need for the delegate declaration:
public EventHandler<SomeEventArgs> eventsWhich is the same as (I think)
private delegate Something(object o, SomeEventArgs e); public event Something events;Is it a good idea to use EventHandler? I can see why sending the object could be useful, but not all the time - and a lot of the time, the EventArgs may just become annoying to deal with.
解决方案Microsoft has definitely pushed some great patterns that has made working with C# a pleasant experience. That being said, I recommend you write your event handlers to be convenient for your client code rather than writing a lot of code just to meet a pattern.
delegate void ClientMessageHandler(IClient client, IMessage message);
更多推荐
我应该使用EventHandler< T>和/或EventArgs委托模式?
发布评论