更新:2007 年 11 月
错误消息
“IndexerName”属性仅在不是显式接口成员声明的索引器上有效
如果您在是接口的显式实现的索引器上使用 IndexerName 属性,则将出现此错误。如果有可能,通过从索引器的声明中移除接口名称,可以避免此错误。有关更多信息,请参见 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()
{
}
}