静态事件处理程序的事件的发件人 [英] Sender of static EventHandler event

查看:86
本文介绍了静态事件处理程序的事件的发件人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类静态事件处理程序事件:

public static event EventHandler MyEvent;

static void RaiseEvent()
{
    EventHandler p = MyEvent;

    if (p != null)
    {
        p(null, EventArgs.Empty);
    }
}

由于我没有任何的对象,可作为事件的发送者,我提出这个事件发送= NULL 。是否确定有这个参​​数设置为null,根据.NET编程指南?如果没有,我可以作为发件人使用什么对象?

Since I don't have any this object which can be used as event sender, I raise this event with sender = null. Is it OK to have this parameter set to null, according to .NET programming guidelines? If not, what object can I use as a sender?

推荐答案

活动设计

在静态的活动,在发件人的参数为空。

On static events, the sender parameter should be null.

来源:<一href="http://msdn.microsoft.com/en-us/library/vstudio/ms229011%28v=vs.100%29.aspx">http://msdn.microsoft.com/en-us/library/vstudio/ms229011%28v=vs.100%29.aspx

这篇关于静态事件处理程序的事件的发件人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆