【发布时间】:2014-05-04 03:15:54
【问题描述】:
在我看来,我对 c# 中的协方差存在理解问题。 如果我有以下课程:
class a {
}
class b : a {
}
class A<T> where T: a {
}
class B<T> : A<T> {
}
class C : A<b> {
}
现在我这样做了:
A<a> t1 = new B<b>();
A<a> t2 = new C();
这些都不起作用 - 但为什么呢? 微软的这篇文章不是建议说这应该有效吗? http://msdn.microsoft.com/de-de/library/dd799517(v=vs.110).aspx
为什么这个非常简单的例子不起作用?
最好的问候
【问题讨论】:
标签: c# generics inheritance covariance