Error del compilador CS0646

Actualización: noviembre 2007

Mensaje de error

No se puede especificar el atributo DefaultMember en un tipo que contenga un indizador
Cannot specify the DefaultMember attribute on a type containing an indexer

Si una clase u otro tipo especifica System.Reflection.DefaultMemberAttribute, no puede contener un indizador. Para obtener más información, vea Propiedades.

El código siguiente genera el error 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;
}