List<T>类是 ArrayList 类的泛型等效类。 该类使用大小可按需动态增加的数组实现 IList<T> 泛型接口。
泛型的好处: 它为使用 c#语言编写面向对象程序增加了极大的效力和灵活性。不会强行对值类型进行装箱和拆箱,或对引用类型进行向下强制类型转换,所以性能得到提高。
a.T为列表中元素类型,现在以string类型作为例子
如: List<string> mList = new List<string>();
b.增加元素:List. Add(T item) 添加一个元素
c.插入元素:Insert(int index, T item); 在index位置添加一个元素
d.删除元素: List. Remove(T item) 删除一个值
List. RemoveAt(int index); 删除下标为index的元素
List. RemoveRange(int index, int count); 从下标index开始,删除count个元素
如.:mList.RemoveRange(3, 2); //超出删除的范围会出错