Error del compilador CS0668

Actualización: noviembre 2007

Mensaje de error

Dos indizadores tienen nombres distintos; el atributo IndexerName se debe utilizar con el mismo nombre en cada indizador de un tipo
Two indexers have different names; the IndexerName attribute must be used with the same name on every indexer within a type

Los valores pasados al atributo IndexerName deben ser los mismos para todos los indizadores de un tipo. Para obtener más información sobre el atributo IndexerName,vea IndexerNameAttribute (Clase).

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