【发布时间】:2017-05-25 01:46:03
【问题描述】:
我搜索了网络和 stackoverflow,发现了许多处理 CS0311 错误的帖子。没有一个场景与我的相似。我有一个从泛型类继承的泛型类。
请注意BusinessBase 是CSLA 框架中的一个类
我错过了什么?
public interface Itest
{
int Digit();
}
class BB : Itest
{
public int Digit()
{
return 20;
}
}
class Test<T> : BusinessBase<T>, Itest where T : Test<T>, Itest
{
public int Digit()
{
return 30;
}
}
Test<Itest> test = new Test<Itest>(); //error CS0311
错误 CS0311 类型
'MyTestApp.Itest'不能用作泛型类型或方法'A<T>'中的类型参数'T'。没有从'MyTestApp.Itest'到'MyTestApp.A<MyTestApp.Itest>'的隐式引用转换。我的测试应用程序
【问题讨论】:
-
你不需要 where 子句中的
Test<T>位,试试where T : Itest -
每个
Test<T>都是Itest但每个Itest都不是Test<T>这就是它失败的原因(就像BB你在那里。Itest可能是BB)
标签: c# generics inheritance interface csla