【发布时间】:2019-01-20 18:47:05
【问题描述】:
我看不出以下代码有什么问题,或者我可以如何修复它。 (也许我误解了泛型。)
class X<I>
where I : ISomeInterface
{ }
class Y<T>
where T : X<ISomeInterface>
{ }
class Z<I>
where I : ISomeInterface
{
Y<X<I>> AData { get; } // What compiler does not like
Y<X<ISomeInterface>> BData { get; } // What compiler likes
}
编译器抱怨它不能在泛型类型Y<T> 中使用X<I> 作为类型参数T。
【问题讨论】:
-
调用/使用此代码的代码在哪里?
-
@ZoharPeled 我的错误,请检查更新的代码示例。
标签: c# .net generics interface covariance