共用方式為


編譯器錯誤 CS0559

更新:2007 年 11 月

錯誤訊息

++ 或 -- 運算子的參數型別必須是包含型別

運算子多載的方法宣告必須遵循某些規定。對於 ++ 和 -- 運算子來說,參數的型別必須與用來多載運算子的型別相同。

範例

下列範例會產生 CS0559:

// CS0559.cs
// compile with: /target:library
public class iii
{
   public static implicit operator int(iii x)
   {
      return 0;
   }

   public static implicit operator iii(int x)
   {
      return null;
   }

   public static int operator ++(int aa)   // CS0559
   // try the following line instead
   // public static iii operator ++(iii aa)
   {
      return (iii)0;
   }
}

下列範例會產生 CS0559。

// CS0559_b.cs
// compile with: /target:library
public struct S
{
   public static S operator ++(S? s) { return new S(); }   // CS0559
   public static S operator --(S? s) { return new S(); }   // CS0559
}

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(); }
}