Compiler Error CS0668
TOC
Collapse the table of content
Expand the table of content
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

Compiler Error CS0668

Two indexers have different names; the IndexerName attribute must be used with the same name on every indexer within a type

The values passed to the IndexerName attribute must be the same for all indexers in a type. For more information on the IndexerName attribute, see IndexerNameAttribute Class.

The following sample generates 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()
   {
   }
}
Show:
© 2016 Microsoft