Compiler Error CS0415
The 'IndexerName' attribute is valid only on an indexer that is not an explicit interface member declaration
This error occurs if you use an IndexerName attribute on an indexer that was an explicit implementation of an interface. This error may be avoided by removing the interface name from the declaration of the indexer, if possible. For more information, see the IndexerNameAttribute Class.
The following sample generates CS0415:
// CS0415.cs
using System;
using System.Runtime.CompilerServices;
public interface IA
{
int this[int index]
{
get;
set;
}
}
public class A : IA
{
[IndexerName("Item")] // CS0415
int IA.this[int index]
// Try this line instead:
// public int this[int index]
{
get { return 0; }
set { }
}
static 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.
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for