class Persons : CollectionBase { public void add(Person p) {
List.Add(p); }
public void remove(Person p) {
List.Remove(p); }
public Person this[int index] { get {
return (Person)List[index]; } } class Person {
public void f() {
Console.WriteLine(\ } } 索引
索引的含义:
类的一个成员,它使得对象可以像数组一样被索引。与其他成员不同的是,索引没有名称。
? 索引的类型指定了元素类型。后面是this关键字 ? 索引声明使用了virtual修饰符时,索引就是虚拟索引
? 索引声明使用了override 修饰符时,该索引就被称为覆盖索引 ? 索引声明使用了abstract修饰符时,该索引就被称为抽象索引 static void Main(string[] args)
{ Person
p[1] = p[0] + 22; Console.WriteLine(p[1]); Console.Read(); } }
class Person
{ public T[] t = new T[10]; public T this[int index] {
get {return t[index ];} set { t[index] = value; } } }