我在重载索引器属性时遇到了问题。
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