重複の可能性:
「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; }
}
}
コンパイラは、this[...]とItemが同じメンバー名を使用していると考えているようです。これは正しい/正常ですか?私はこれまでこれに出くわしたことがないことに驚いています。