可能重复:
Class with indexer and property named “Item”项目,这[] - 会员使用相同的名称已经宣布
横跨东西我从来没见过刚来到,想知道为什么可能会发生?
对于“Item”和“this [...]”,我得到编译器错误“已经声明同名的成员”。
public class SomeClass : IDataErrorInfo
{
public int Item { get; set; }
public string this[string propertyName]
{
get
{
if (propertyName == "Item" && Item <= 0)
{
return "Item must be greater than 0";
}
return null;
}
}
public string Error
{
get { return null; }
}
}
编译器似乎认为这个[...]和Item使用相同的成员名称。这是正确的还是正常的?我很惊讶我以前没有遇到过这种情况。
这是重复的。看到这个SO问题的答案:http://stackoverflow.com/questions/5110403/class-with-indexer-and-property-named-item。 –