索引器 小实例
时间:2010-11-06 来源:web开发
public class Collections<T>
{
private T[] arr;
public T[] Arr
{
get { return arr; }
set { arr = value; }
}
public T this[int index]
{
get { return arr[index]; }
set { this.arr[index] = value; }
}
public T this[string value]
{
}
}
应用
static void Main(string[] args)
{
Collections<string> cts = new Collections<string>();
cts.Arr=new string[100];
cts[0] = "string1";
cts[1] = "string2";
Console.WriteLine(cts[0]+" "+cts[1]);
Console.ReadLine();
}