复制代码
public class Person
{
string[] PersonList = new string[10];
public string this[int param]
{
get { return PersonList[param]; }
set { PersonList[param] = value; }
}
}
Person person = new Person();
person[0] = "hello";
person[1] = "world";
Console.WriteLine(person[0]);
注:相关教程知识阅读请移步到c#教程频道。
public class Person
{
string[] PersonList = new string[10];
public string this[int param]
{
get { return PersonList[param]; }
set { PersonList[param] = value; }
}
}
其中索引的数据类型必须与索引器的索引类型相同。例如:
复制代码
Person person = new Person();
person[0] = "hello";
person[1] = "world";
Console.WriteLine(person[0]);
看起来对象像个数组一样,呵呵。
注:相关教程知识阅读请移步到c#教程频道。










