共用方式為


編譯器錯誤 CS0620

更新:2007 年 11 月

錯誤訊息

索引子不能有 void 的型別

索引子的傳回型別不可為 void。索引子必須傳回一個值。

下列範例會產生 CS0620:

// CS0620.cs
class MyClass
{
   public static void Main()
   {
      MyClass test = new MyClass();
      System.Console.WriteLine(test[2]);
   }

   void this [int intI]   // CS0620, return type cannot be void
   {
      get
      {
         // will need to return some value
      }
   }
}

請參閱

參考

void (C# 參考)