例如,在我的库中我有这样的东西:
public delegate void LostConnectionEventHandler(string address); public delegate void MessageReceieved(byte[] bytes);
这是什么标准做法?我应该用MessageEventArgs替换字符串地址和用MessageEventArgs替换byte []字节吗?
我知道其中任何一个工作得很好而且这个问题可能是主观的但我仍然对高级程序员在决定是否包含他们自己的EventArgs或仅直接传递数据时所经历的思考过程感到好奇.
谢谢!
解决方法
The .NET Framework guidelines indicate that the delegate type used for
an event should take two parameters,an “object source” parameter
indicating the source of the event,and an “e” parameter that
encapsulates any additional information about the event. The type of
the “e” parameter should derive from the EventArgs class. For events
that do not use any additional information,the .NET Framework has
already defined an appropriate delegate type: EventHandler.
参考:http://msdn.microsoft.com/en-us/library/aa645739(v=vs.71).aspx
另一个有用的信息:http://msdn.microsoft.com/en-us/library/ms229011.aspx