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

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

          <bdo id='ZPqAf'></bdo><ul id='ZPqAf'></ul>
      2. <tfoot id='ZPqAf'></tfoot>

      3. 为什么事件处理程序的返回类型总是 void?

        时间:2023-09-15
        • <bdo id='2vmbq'></bdo><ul id='2vmbq'></ul>
          <tfoot id='2vmbq'></tfoot>

          <small id='2vmbq'></small><noframes id='2vmbq'>

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

              • <legend id='2vmbq'><style id='2vmbq'><dir id='2vmbq'><q id='2vmbq'></q></dir></style></legend>
                  <tbody id='2vmbq'></tbody>
                  本文介绍了为什么事件处理程序的返回类型总是 void?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  哎,我就纳闷了,为啥事件的返回类型比如

                  Hey, I wondered why is it that the return type of events such as

                  private void button1_Click(object sender, EventArgs e)
                  

                  总是无效的?

                  它也可以返回任何其他值吗?

                  Can it return any other value too?

                  推荐答案

                  一个事件处理程序签名,即返回类型和它接受的参数的数量和类型,由 delegate 的签名决定 用于定义事件.所以你的例子中 Button 的 Click 事件不支持任何返回值.

                  An event handler signature, that is the return type and the number and types of arguments it takes, are determined by the signature of the delegate used to define the event. So the Click event of the Button in your example does not support any return values.

                  通常,您不会期望从事件处理程序返回一个值作为函数返回值,因为一个事件可以有多个订阅者,并且每个订阅者都将独立于其他处理程序返回一个返回值,并且需要特殊的事件触发代码来决定如何处理所有返回值.

                  Typically you would not expect to return a value from an event handler as a function return value because an event can have multiple subscribers and each would be returning a return value independently of the other handlers and would require special event firing code to decide what to do with all the return values.

                  通常,如果您需要从事件处理程序返回通信,则 EventArgs 结构将包含处理程序可以更新的成员,并且每个处理程序将有机会查看值并相应地更新,并且触发事件的代码只需要对结构中的最终值做出反应.

                  Typically, if you need to communicate back from an event handler the EventArgs structure would contain members that the handler can update and each handler will get an opportunity to look at the values and update accordingly, and the code firing the event only needs to react to the final value in the structure.

                  这篇关于为什么事件处理程序的返回类型总是 void?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使事件处理程序异步运行? 下一篇:带有自定义参数的 EventHandler

                  相关文章

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

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

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

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