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

      1. <legend id='aexC5'><style id='aexC5'><dir id='aexC5'><q id='aexC5'></q></dir></style></legend>
          <bdo id='aexC5'></bdo><ul id='aexC5'></ul>

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

        在事件声明中添加匿名空委托有缺点吗?

        Is there a downside to adding an anonymous empty delegate on event declaration?(在事件声明中添加匿名空委托有缺点吗?)

        <tfoot id='c4LE0'></tfoot>

                <tbody id='c4LE0'></tbody>
            • <i id='c4LE0'><tr id='c4LE0'><dt id='c4LE0'><q id='c4LE0'><span id='c4LE0'><b id='c4LE0'><form id='c4LE0'><ins id='c4LE0'></ins><ul id='c4LE0'></ul><sub id='c4LE0'></sub></form><legend id='c4LE0'></legend><bdo id='c4LE0'><pre id='c4LE0'><center id='c4LE0'></center></pre></bdo></b><th id='c4LE0'></th></span></q></dt></tr></i><div id='c4LE0'><tfoot id='c4LE0'></tfoot><dl id='c4LE0'><fieldset id='c4LE0'></fieldset></dl></div>
            • <small id='c4LE0'></small><noframes id='c4LE0'>

                • <bdo id='c4LE0'></bdo><ul id='c4LE0'></ul>
                  <legend id='c4LE0'><style id='c4LE0'><dir id='c4LE0'><q id='c4LE0'></q></dir></style></legend>
                  本文介绍了在事件声明中添加匿名空委托有缺点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我看到有人提到过这个成语(包括关于 SO):

                  I have seen a few mentions of this idiom (including on SO):

                  // Deliberately empty subscriber
                  public event EventHandler AskQuestion = delegate {};
                  

                  好处很明显 - 它避免了在引发事件之前检查 null 的需要.

                  The upside is clear - it avoids the need to check for null before raising the event.

                  但是,我很想知道是否有任何缺点.例如,它是否被广泛使用并且足够透明以至于不会引起维护问题?空事件订阅者调用是否有任何明显的性能影响?

                  However, I am keen to understand if there are any downsides. For example, is it something that is in widespread use and is transparent enough that it won't cause a maintenance headache? Is there any appreciable performance hit of the empty event subscriber call?

                  推荐答案

                  唯一的缺点是非常轻微的性能损失,因为您调用了额外的空委托.除此之外,没有维护费用或其他缺点.

                  The only downside is a very slight performance penalty as you are calling extra empty delegate. Other than that there is no maintenance penalty or other drawback.

                  这篇关于在事件声明中添加匿名空委托有缺点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
                  Parameter count mismatch with Invoke?(参数计数与调用不匹配?)
                  How to store delegates in a List(如何将代表存储在列表中)
                  How delegates work (in the background)?(代表如何工作(在后台)?)
                  C# Asynchronous call without EndInvoke?(没有 EndInvoke 的 C# 异步调用?)
                  Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
                  <tfoot id='NEetA'></tfoot>
                    <tbody id='NEetA'></tbody>
                  <i id='NEetA'><tr id='NEetA'><dt id='NEetA'><q id='NEetA'><span id='NEetA'><b id='NEetA'><form id='NEetA'><ins id='NEetA'></ins><ul id='NEetA'></ul><sub id='NEetA'></sub></form><legend id='NEetA'></legend><bdo id='NEetA'><pre id='NEetA'><center id='NEetA'></center></pre></bdo></b><th id='NEetA'></th></span></q></dt></tr></i><div id='NEetA'><tfoot id='NEetA'></tfoot><dl id='NEetA'><fieldset id='NEetA'></fieldset></dl></div>

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

                          <bdo id='NEetA'></bdo><ul id='NEetA'></ul>

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