更新:2007 年 11 月
错误消息
两个索引器的名称不同;类型中的每个索引器上都必须用相同的名称使用 IndexerName 属性
对于类型中的所有索引器,传递给 IndexerName 属性的值必须是相同的。有关 IndexerName 属性的更多信息,请参见 IndexerNameAttribute 类。
下面的示例生成 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()
{
}
}