編譯器錯誤 CS0460
更新: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
}