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

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

    <tfoot id='WGpA7'></tfoot>

        • <bdo id='WGpA7'></bdo><ul id='WGpA7'></ul>

      1. 简单委托(委托)与多播委托

        时间:2023-11-11

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

            <tfoot id='Bvbzd'></tfoot>

            • <legend id='Bvbzd'><style id='Bvbzd'><dir id='Bvbzd'><q id='Bvbzd'></q></dir></style></legend>
              <i id='Bvbzd'><tr id='Bvbzd'><dt id='Bvbzd'><q id='Bvbzd'><span id='Bvbzd'><b id='Bvbzd'><form id='Bvbzd'><ins id='Bvbzd'></ins><ul id='Bvbzd'></ul><sub id='Bvbzd'></sub></form><legend id='Bvbzd'></legend><bdo id='Bvbzd'><pre id='Bvbzd'><center id='Bvbzd'></center></pre></bdo></b><th id='Bvbzd'></th></span></q></dt></tr></i><div id='Bvbzd'><tfoot id='Bvbzd'></tfoot><dl id='Bvbzd'><fieldset id='Bvbzd'></fieldset></dl></div>
                • <bdo id='Bvbzd'></bdo><ul id='Bvbzd'></ul>
                    <tbody id='Bvbzd'></tbody>
                  本文介绍了简单委托(委托)与多播委托的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我浏览了很多文章,但我仍然不清楚我们通常创建的普通委托和多播委托之间的区别.

                  I have gone through many articles but I am still not clear about the difference between the normal delegates that we usually create and multicast delegates.

                  public delegate void MyMethodHandler(object sender);
                  MyMethodHandler handler = new MyMethodHandler(Method1);
                  handler += Method2;
                  handler(someObject);
                  

                  上面的委托 MyMethodHandler 会调用这两个方法.现在多播委托从何而来.我读过他们可以调用多种方法,但我担心我对委托的基本理解是不正确的.

                  The above delegate MyMethodHandler will call these two methods. Now where does multicast delegates come in. I have read that they can call multiple methods but I am afraid that my basic understanding about delegates is not correct.

                  推荐答案

                  这篇文章 解释得很好:

                  delegate void Del(string s);
                  
                  class TestClass
                  {
                      static void Hello(string s)
                      {
                          System.Console.WriteLine("  Hello, {0}!", s);
                      }
                  
                      static void Goodbye(string s)
                      {
                          System.Console.WriteLine("  Goodbye, {0}!", s);
                      }
                  
                      static void Main()
                      {
                          Del a, b, c, d;
                  
                          // Create the delegate object a that references 
                          // the method Hello:
                          a = Hello;
                  
                          // Create the delegate object b that references 
                          // the method Goodbye:
                          b = Goodbye;
                  
                          // The two delegates, a and b, are composed to form c: 
                          c = a + b;
                  
                          // Remove a from the composed delegate, leaving d, 
                          // which calls only the method Goodbye:
                          d = c - a;
                  
                          System.Console.WriteLine("Invoking delegate a:");
                          a("A");
                          System.Console.WriteLine("Invoking delegate b:");
                          b("B");
                          System.Console.WriteLine("Invoking delegate c:");
                          c("C");
                          System.Console.WriteLine("Invoking delegate d:");
                          d("D");
                      }
                  }
                  /* Output:
                  Invoking delegate a:
                    Hello, A!
                  Invoking delegate b:
                    Goodbye, B!
                  Invoking delegate c:
                    Hello, C!
                    Goodbye, C!
                  Invoking delegate d:
                    Goodbye, D!
                  */
                  

                  这篇关于简单委托(委托)与多播委托的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Control.BeginInvoke 的 MethodInvoker 与 Action 下一篇:代言人有什么好处?

                  相关文章

                    • <bdo id='Y1y23'></bdo><ul id='Y1y23'></ul>
                    <tfoot id='Y1y23'></tfoot>

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

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