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()
{
}
}
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET feedback
.NET is an open source project. Select a link to provide feedback: