我在重載索引器屬性時遇到了問題。
C中的問題重載索引器#
public class ClassName
{
private int[] a;
private int[] b;
private string[] c;
private string[] d;
public int this[int pos]
{
get{ return a[pos];}
set{a[pos] = value;}
}
public int this[int pos]
{
get{ return b[pos];}
set{b[pos] = value;}
}
public int this[int pos]
{
get{ return c[pos];}
set{c[pos] = value;}
}
public int this[int pos]
{
get{ return d[pos];}
set{d[pos] = value;}
}
}
我越來越Error 1 'Class1 variables' already defines a member called 'this' with the same parameter types
請建議我如何實現這一點?
的問題是,你不重載索引器 - 你已經指定了4次相同的簽名(另外,我認爲其中兩個應該返回'string')。我不認爲C#支持命名索引器,所以你可能想重新考慮你的設計。 – 2010-05-26 07:21:32