转帖地址
http://tech.sina.com.cn/s/2005-11-24/1417774632.shtml
using System.Collections;
public class List1<T> : CollectionBase
{
public List1() { }
public T this[int index]
{
get { return (T)List[index]; }
set { List[index] = value; }
}
public int Add(T value)
{
return List.Add(value);
}
}
这里需要一个索引器
索引器(Indexer):官方说法是一种类成员,它允许类或结构的实例按与数组相同的方式排序,索引器与属性类似,只不过索引器的gei和set访问器方法带有参数,而属性访问器方法不带参数。
public T this[int index]
{
get { return (T)List[index]; }
set { List[index] = value; }
}