Skip to main content
 首页 » 编程设计

c#之委托(delegate)类的用例

2024年02月13日15zdz8207

<分区>

由于 MulticastDelegate 是 .NET 的主要委托(delegate)类,我想问一下,是否有任何使用 Delegate 类的用例?

我的意思是,如果我有一个类型为 Delegate 的变量和另一个类型为 MulticastDelegate 的变量,则不同的方法覆盖(例如 GetInvocationList)将是已调用,但如果每个单个程序员定义的委托(delegate)都继承自 MulticastDelegate,那么使用 Delegate 类的意义何在?

如果我假设没有,难道不应该用 ObsoleteAttribute 标记并注释以使用 MulticastDelegate 吗?

或者编译器不应该默默地将“Delegate variable1;”更改为“MulticastDelegate variable1;”?