相关疑难解决方法(0)

为什么TEventArgs在.NET生态系统的标准事件模式中没有逆变?

在.NET中了解有关标准事件模型的更多信息时,我发现在引入C#中的泛型之前,处理事件的方法由此委托类型表示:

//
// Summary:
//     Represents the method that will handle an event that has no event data.
//
// Parameters:
//   sender:
//     The source of the event.
//
//   e:
//     An object that contains no event data.
public delegate void EventHandler(object sender, EventArgs e);
Run Code Online (Sandbox Code Playgroud)

但是在C#2中引入泛型之后,我认为这个委托类型是使用泛型重写的:

//
// Summary:
//     Represents the method that will handle an event when the event provides data.
//
// Parameters:
//   sender:
//     The source of the event.
//
//   e:
// …
Run Code Online (Sandbox Code Playgroud)

.net c# contravariance .net-core

23
推荐指数
1
解决办法
918
查看次数

标签 统计

.net ×1

.net-core ×1

c# ×1

contravariance ×1