共用方式為


編譯器錯誤 CS0415

更新:2007 年 11 月

錯誤訊息

'IndexerName' 屬性只在非明確介面成員宣告的索引子上有效

如果您在原來是明確介面實作的索引子上使用 IndexerName 屬性 (Attribute),便會發生這個錯誤。如果能從索引子的宣告中移除介面名稱,就可避免發生這個錯誤。如需詳細資訊,請參閱 IndexerNameAttribute 類別

下列範例會產生 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()
    {
    }
}