<tfoot id='o4Y7u'></tfoot>

    1. <i id='o4Y7u'><tr id='o4Y7u'><dt id='o4Y7u'><q id='o4Y7u'><span id='o4Y7u'><b id='o4Y7u'><form id='o4Y7u'><ins id='o4Y7u'></ins><ul id='o4Y7u'></ul><sub id='o4Y7u'></sub></form><legend id='o4Y7u'></legend><bdo id='o4Y7u'><pre id='o4Y7u'><center id='o4Y7u'></center></pre></bdo></b><th id='o4Y7u'></th></span></q></dt></tr></i><div id='o4Y7u'><tfoot id='o4Y7u'></tfoot><dl id='o4Y7u'><fieldset id='o4Y7u'></fieldset></dl></div>
      • <bdo id='o4Y7u'></bdo><ul id='o4Y7u'></ul>

      1. <small id='o4Y7u'></small><noframes id='o4Y7u'>

        <legend id='o4Y7u'><style id='o4Y7u'><dir id='o4Y7u'><q id='o4Y7u'></q></dir></style></legend>
      2. 为事件定义一个空的委托主体是一个好习惯吗?

        时间:2023-11-11
        <i id='6atwT'><tr id='6atwT'><dt id='6atwT'><q id='6atwT'><span id='6atwT'><b id='6atwT'><form id='6atwT'><ins id='6atwT'></ins><ul id='6atwT'></ul><sub id='6atwT'></sub></form><legend id='6atwT'></legend><bdo id='6atwT'><pre id='6atwT'><center id='6atwT'></center></pre></bdo></b><th id='6atwT'></th></span></q></dt></tr></i><div id='6atwT'><tfoot id='6atwT'></tfoot><dl id='6atwT'><fieldset id='6atwT'></fieldset></dl></div>
        <tfoot id='6atwT'></tfoot>

              <bdo id='6atwT'></bdo><ul id='6atwT'></ul>
            • <legend id='6atwT'><style id='6atwT'><dir id='6atwT'><q id='6atwT'></q></dir></style></legend>
                <tbody id='6atwT'></tbody>

                  <small id='6atwT'></small><noframes id='6atwT'>

                1. 本文介绍了为事件定义一个空的委托主体是一个好习惯吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  可能重复:
                  添加有缺点吗事件声明上的匿名空委托?

                  为事件定义一个空的委托主体,这样您就不必担心引发没有事件处理程序的事件,这是一种好习惯吗?(无需检查事件是否为空).

                  Is it a good practice to define an empty delegate body for a event so that you do not need to worry raise a event which have no event handler? ( no need to check whether event is null).

                  如下代码:

                  public event EventHandler<LoadEventArgs> LoadedData = delegate { };
                  

                  推荐答案

                  我确实发现它很有用,是的.会有非常小的性能成本 - 但不必执行无效测试的可读性优势使其值得 IMO.

                  I've certainly found it useful, yes. There will be a tiny, tiny performance cost - but the benefit in readability for not having to perform the nullity test makes it worth it IMO.

                  值得指出的是,这是少数使用匿名方法而不是 lambda 表达式更好的情况之一 - 否则您必须命名将要忽略的参数,如下所示:

                  It's worth pointing out that this is one of the few times when it's good to use an anonymous method rather than a lambda expression - otherwise you have to name the parameters that you're going to ignore, like this:

                  public event EventHandler<LoadEventArgs> LoadedData = (sender, args) => {};
                  

                  我不喜欢为我不打算使用的东西命名:)

                  I don't like having to name things I'm not intending to use :)

                  这篇关于为事件定义一个空的委托主体是一个好习惯吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 Action.Invoke 是否被认为是最佳实践? 下一篇:从属性 getter 或 setter 方法创建委托

                  相关文章

                  <legend id='RSwmy'><style id='RSwmy'><dir id='RSwmy'><q id='RSwmy'></q></dir></style></legend>

                  <small id='RSwmy'></small><noframes id='RSwmy'>

                    <bdo id='RSwmy'></bdo><ul id='RSwmy'></ul>
                  <i id='RSwmy'><tr id='RSwmy'><dt id='RSwmy'><q id='RSwmy'><span id='RSwmy'><b id='RSwmy'><form id='RSwmy'><ins id='RSwmy'></ins><ul id='RSwmy'></ul><sub id='RSwmy'></sub></form><legend id='RSwmy'></legend><bdo id='RSwmy'><pre id='RSwmy'><center id='RSwmy'></center></pre></bdo></b><th id='RSwmy'></th></span></q></dt></tr></i><div id='RSwmy'><tfoot id='RSwmy'></tfoot><dl id='RSwmy'><fieldset id='RSwmy'></fieldset></dl></div>
                    1. <tfoot id='RSwmy'></tfoot>