1. <tfoot id='7UNtm'></tfoot>

    2. <small id='7UNtm'></small><noframes id='7UNtm'>

        <bdo id='7UNtm'></bdo><ul id='7UNtm'></ul>

    3. <legend id='7UNtm'><style id='7UNtm'><dir id='7UNtm'><q id='7UNtm'></q></dir></style></legend>

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

        在 C# 中是否有一个不是 MulticastDelegate 的委托?

        Is there a Delegate which isn#39;t a MulticastDelegate in C#?(在 C# 中是否有一个不是 MulticastDelegate 的委托?)
        <i id='UxUid'><tr id='UxUid'><dt id='UxUid'><q id='UxUid'><span id='UxUid'><b id='UxUid'><form id='UxUid'><ins id='UxUid'></ins><ul id='UxUid'></ul><sub id='UxUid'></sub></form><legend id='UxUid'></legend><bdo id='UxUid'><pre id='UxUid'><center id='UxUid'></center></pre></bdo></b><th id='UxUid'></th></span></q></dt></tr></i><div id='UxUid'><tfoot id='UxUid'></tfoot><dl id='UxUid'><fieldset id='UxUid'></fieldset></dl></div>

        • <legend id='UxUid'><style id='UxUid'><dir id='UxUid'><q id='UxUid'></q></dir></style></legend><tfoot id='UxUid'></tfoot>
            <tbody id='UxUid'></tbody>
        • <small id='UxUid'></small><noframes id='UxUid'>

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

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

                  问题描述

                  我认为答案是否定的?如果没有,为什么我们要分开 DelegateMulticastDelegate 类?也许又是因为其他一些 .NET 语言"?

                  I think the answer is NO? If there isn't, why do we have separated Delegate and MulticastDelegate classes? Maybe it's again because of "some other .NET languages"?

                  推荐答案

                  认为这是 ECMA 335 的一部分,但我在任何地方都看不到它.

                  I thought this was part of ECMA 335, but I can't see it in there anywhere.

                  你不能在 C# 中创建这样的委托类型,但你可以在 IL 中:

                  You can't create such a delegate type in C#, but you can in IL:

                  .class public auto ansi sealed Foo
                         extends [mscorlib]System.Delegate
                  {
                      // Body as normal
                  }
                  

                  C# 编译器使用这样的委托没有问题:

                  The C# compiler has no problems using such a delegate:

                  using System;
                  
                  class Test
                  {
                      static void Main()
                      {
                          Foo f = x => Console.WriteLine(x);
                          f("hello");
                      }
                  }
                  

                  但是 CLR 在尝试加载它时会这样做:

                  But the CLR does when it tries to load it:

                  未处理的异常:System.TypeLoadException:无法从程序集Foo,Version=0.0.0.0,Culture=neutral,PublicKeyToken=null"加载类型Foo",因为它不能直接从委托类继承.在 Test.Main()

                  Unhandled Exception: System.TypeLoadException: Could not load type 'Foo' from assembly 'Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because it cannot inherit directly from the delegate class. at Test.Main()

                  基本上,Delegate/MulticastDelegate 分离是一个历史性的意外.我相信早期的 alpha/beta 版本确实做出了区分,但事实证明它太混乱而且通常没有用 - 所以现在 每个 委托都派生自 MulticastDelegate.

                  Basically the Delegate/MulticastDelegate separation is an historical accident. I believe that early alpha/beta versions did make the distinction, but it proved too confusing and generally not useful - so now every delegate derives from MulticastDelegate.

                  (有趣的是,C# 规范在不能用作泛型约束的类型列表中只提到了一次 MulticastDelegate.)

                  (Interestingly, the C# specification only mentions MulticastDelegate once, in the list of types which can't be used as generic constraints.)

                  这篇关于在 C# 中是否有一个不是 MulticastDelegate 的委托?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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='U4Nmb'></tfoot>

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

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

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

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