c#索引器如何定义不同的访问方式

来源:百度知道 编辑:UC知道 时间:2024/06/21 14:27:56

关键代码:
//基本索引器 根据数组下标查找
public Student this[int index]
{
get { return students[index]; }
}
//重载的索引器 根据姓名查找
public Student this[string name]
{
get{
bool found = false;
for (int i = 0; i < students.Length; i++)
{
if (students[i].Name == name)
{
found = true;
break;
}
}
if (found)
{
return students[i];
}
else
{
return null;
}
}
}

什么意思?
访问方式这四个字非官方正式名词,不明白什么意思.
举个例子吧.

重载this[]方法,想有几种就重载几个
方法。