コンパイラ エラー CS0646

更新 : 2007 年 11 月

エラー メッセージ

インデクサを含む型に対して DefaultMember 属性を指定できません。

クラスまたはその他の型で System.Reflection.DefaultMemberAttribute を指定する場合は、インデクサを含めることはできません。詳細については、「プロパティ」を参照してください。

次の例では 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;
}