以下代码编译失败:
class MyClass<T> : where T : MyClass <T>{}
有什么办法可以解决吗? 我使用了以下解决方法,但我想知道是否有更好的方法
class MyClass <T> : IMyClass where T : IMyClass {}
interface IMyClass {}
最佳答案
只有当你想从基类派生类或实现接口(interface)时,才需要在类名后加上冒号:
class MyClass<T> where T : MyClass<T>
// ↑
// no ':' here
关于c# - 使用 Generics C# 3.5 时出现编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2967133/