共用方式為


編譯器錯誤 CS0668

更新:2007 年 11 月

錯誤訊息

兩個索引子具有不同的名稱 ; 在型別中每一索引子上 IndexerName 屬性必須使用相同的名稱

傳遞給 IndexerName 屬性 (Attribute) 的值必須和型別中所有索引子 (Indexer) 的值相同。如需 IndexerName 屬性的詳細資訊,請參閱 IndexerNameAttribute 類別

下列範例會產生 CS0668:

// CS0668.cs
using System;
using System.Runtime.CompilerServices;

class IndexerClass
{
   [IndexerName("IName1")]
   public int this [int index]   // indexer declaration
   {
      get
      {
         return index;
      }
      set
      {
      }
   }

   [IndexerName("IName2")]
   public int this [string s]    // CS0668, change IName2 to IName1
   {
      get
      {
         return int.Parse(s);
      }
      set
      {
      }
   }

   void Main()
   {
   }
}