程序代码中 pos和data这个两个索引器各自起到了什么作用 解释下 谢谢
class OvrIndexer{
private string[] myData;
private int arrSize;
public OvrIndexer(int size)
{
arrSize = size;
myData = new string[size];
for (int i = 0; i < size; i++)
{
myData[i] = "empty";
}
}
public string this[int pos]
{
get
{
return myData[pos];
}
set
{
myData[pos] = value;
}
}
public string this[string data]
{
get
{
int count = 0;
for (int i = 0; i < arrSize; i++)
{
if (myData[i] == data)
{
count++;
}
}
return count.ToString();
}
set
{
for (int i = 0; i < arrSize; i++)
{
if (myData[i] == data)
{
myData[i] = value;
}
}
}
}