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

<small id='3B8Gf'></small><noframes id='3B8Gf'>

    1. <legend id='3B8Gf'><style id='3B8Gf'><dir id='3B8Gf'><q id='3B8Gf'></q></dir></style></legend>

      <tfoot id='3B8Gf'></tfoot>

        <bdo id='3B8Gf'></bdo><ul id='3B8Gf'></ul>

        我是否应该实例化一个新的委托?

        时间:2023-09-15

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

        <legend id='kblou'><style id='kblou'><dir id='kblou'><q id='kblou'></q></dir></style></legend>
          <tbody id='kblou'></tbody>

          <tfoot id='kblou'></tfoot>

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

                  本文介绍了我是否应该实例化一个新的委托?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我刚刚意识到我可以通过两种方式添加事件处理程序:

                  I just realized I can add an event handler in two ways:

                  考虑这样的事件处理程序:

                  Consider an event handler like so:

                  private void MyEventHandler()
                  {}
                  

                  方法一:实例化一个新的委托

                  Method 1: Instantiate a new delegate

                  MyObject.MyEvent += new Action(MyEventHandler);
                  

                  方法 2:添加事件处理程序而不实例化新委托

                  Method 2: Add event handler without instantiating a new delegate

                  MyObject.MyEvent += MyEventHandler;
                  

                  这两种实现之间有什么区别需要考虑吗?

                  Is there any difference in between these two implementations that should be considered?

                  推荐答案

                  没有区别,生成的IL是一样的..net/c# 2.0 中引入了较短的形式作为一种便利功能,尽管 Visual Studio 仍然在 Tab Completion 上使用第一种形式.

                  There is no difference, the generated IL is the same. The shorter form was introduced in .net/c# 2.0 as a convenience function, although Visual Studio still does the first form on Tab Completion.

                  有关更多信息,请参阅此问题.

                  See this question for some more info.

                  这篇关于我是否应该实例化一个新的委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何删除所有 Click 事件处理程序? 下一篇:何时连接事件处理程序 asp.net

                  相关文章

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

                      <tfoot id='8NEVl'></tfoot>

                    1. <legend id='8NEVl'><style id='8NEVl'><dir id='8NEVl'><q id='8NEVl'></q></dir></style></legend>