为什么要委托类型是从MulticastDelegate类派生为什么不直接从代理类派生? [英] Why delegate types are derived from MulticastDelegate class why not it directly derive from Delegate class?

查看:168
本文介绍了为什么要委托类型是从MulticastDelegate类派生为什么不直接从代理类派生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有关于委托类型一个非常基本的问题。我比较代表和MulticastDelegate类的对象浏览器中的承包商,​​客人,我无法找到任何新的附加成员present在MulticastDelegate。我也注意到,委托类有GetInvocationList虚方法。所以,我认为Delegate类应保持引用多个方法的能力。如果我的假设是正确的我不知道为什么没有自定义的委托类型直接从代理类而不是MulticastDelegate类派生。不知道我在这里缺少什么。请帮我理解上的差异。

I have a very basic question regarding delegate types. I compared the memebers of Delegate and MulticastDelegate classes in object browser and I couldn't find any new additional member present in MulticastDelegate. I also noticed that the Delegate class has GetInvocationList virtual method. So I assume that the Delegate class should have the capability to hold references to multiple methods. If my assumption is correct I wonder why not custom delegate types directly derive from the Delegate class instead of MulticastDelegate class. Not sure what I am missing here. Please help me understand the difference.

推荐答案

代表的基本分割 MulticastDelegate 是历史原因。本来有打算是代表其的无法的结合以及那些可能......但竟然不是一个有用的区别。显然,这是只有在发现这是一个有点来不及撕 MulticastDelegate 出框架/ CLR的。

Basically the split of Delegate and MulticastDelegate is for historical reasons. Originally there were going to be delegates which couldn't be combined and ones which could... but that turned out not to be a useful distinction. Apparently that was only discovered when it was a bit too late to rip MulticastDelegate out of the framework/CLR.

这是通过C#CLR,第3版:

From CLR via C#, 3rd edition:

的System.MulticastDelegate类是从System.Delegate衍生,其本身从System.Object而得。之所以有两个委托类是历史的和不幸的;应在FCL只是一个委托类。可悲的是,你需要知道这两个类的,因为即使你创建所有委托类型有MulticastDelegate作为基类,你会偶尔通过使用Delegate类,而不是MulticastDelegate类中定义的方法操纵你的委托类型。 [...]

The System.MulticastDelegate class is derived from System.Delegate, which is itself derived from System.Object. The reason why there are two delegate classes is historical and unfortunate; there should be just one delegate class in the FCL. Sadly, you need to be aware of both of these classes because even though all delegate types you create have MulticastDelegate as a base class, you'll occasionally manipulate your delegate types by using methods defined by the Delegate class instead of the MulticastDelegate class. [...]

这篇关于为什么要委托类型是从MulticastDelegate类派生为什么不直接从代理类派生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆