This documentation is archived and is not being maintained.

Compiler Error CS0415 

Error Message

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()
    {
    }
}
Show: