更新:2007 年 11 月
错误消息
重写和显式接口实现方法的约束是从基方法继承的,因此不能直接指定这些约束
当作为派生类一部分的泛型方法重写基类中的方法时,不能对重写方法指定约束。派生类中的重写方法从基类的方法中继承它的约束。
示例
下面的示例生成 CS0460。
// CS0460.cs
// compile with: /target:library
class BaseClass
{
BaseClass() { }
}
interface I
{
void F1<T>() where T : BaseClass;
void F2<T>() where T : struct;
void F3<T>() where T : BaseClass;
}
class ExpImpl : I
{
void I.F1<T>() where T : BaseClass {} // CS0460
void I.F2<T>() where T : class {} // CS0460
}