我有静态 EventHandler
事件类:
public static event EventHandler MyEvent;
static void RaiseEvent()
{
EventHandler p = MyEvent;
if (p != null)
{
p(null, EventArgs.Empty);
}
}
因为我没有任何可用作事件发送者的 this
对象,所以我使用 sender = null
引发此事件。根据 .NET 编程指南,将此参数设置为 null 是否可以?如果不是,我可以使用什么对象作为发件人?
最佳答案
事件设计
On static events, the sender parameter should be null
来源:https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms229011(v=vs.100)
关于c# - 静态 EventHandler 事件的发送者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17856823/