編譯器錯誤 CS0448
更新:2007 年 11 月
錯誤訊息
++ 或 -- 運算子的傳回型別必須是包含型別或衍生自包含型別
當您覆寫 ++ 或 -- 運算子時,它們必須傳回與包含型別相同的型別,或傳回衍生自包含型別的型別。
範例
下列範例會產生 CS0448。
// CS0448.cs
class C5
{
public static int operator ++(C5 c) { return null; } // CS0448
public static C5 operator --(C5 c) { return null; } // OK
public static void Main() {}
}
下列範例會產生 CS0448。
// CS0448_b.cs
public struct S
{
public static S? operator ++(S s) { return new S(); } // CS0448
public static S? operator --(S s) { return new S(); } // CS0448
}
public struct T
{
// OK
public static T operator --(T t) { return new T(); }
public static T operator ++(T t) { return new T(); }
public static T? operator --(T? t) { return new T(); }
public static T? operator ++(T? t) { return new T(); }
public static void Main() {}
}