共用方式為


編譯器錯誤 CS0646

更新:2007 年 11 月

錯誤訊息

無法在包含索引子的型別上指定 DefaultMember 屬性

如果類別或其他型別指定 System.Reflection.DefaultMemberAttribute,就不能包含索引子 (Indexer)。如需詳細資訊,請參閱屬性

下列範例會產生 CS0646:

// CS0646.cs
// compile with: /target:library
[System.Reflection.DefaultMemberAttribute("x")]   // CS0646
class MyClass
{
   public int this[int index]   // an indexer
   {
      get
      {
         return 0;
      }
   }

   public int x = 0;
}

// OK
[System.Reflection.DefaultMemberAttribute("x")]
class MyClass2
{
   public int prop
   {
      get
      {
         return 0;
      }
   }

   public int x = 0;
}

class MyClass3
{
   public int this[int index]   // an indexer
   {
      get
      {
         return 0;
      }
   }

   public int x = 0;
}