ArrayList
System.Collections.ArrayList类是一个特殊的数组。通过添加和删除元素,就可以动态改变数组的长度。
一.优点
1。支持自动改变大小的功能
2。可以灵活的插入元素
3。可以灵活的删除元素
二.局限性
跟一般的数组比起来,速度上差些
三.添加元素
1. public virtual int Add(object value);
将对象添加到 ArrayList 的结尾处
ArrayList aList = new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
内容为a b c d e
2. public virtual void Insert(int index,object value);
将元素插入 ArrayList 的指定索引处
ArrayList aList = new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
aList.Insert(0,"aa");
结果为aa a b c d e
3. public virtual void InsertRange(int index,ICollection c);
将集合中的某个元素插入 ArrayList 的指定索引处
ArrayList aList = new ArrayList();
aList.Add("a");
aList.Add("b");
aList.Add("c");
aList.Add("d");
aList.Add("e");
ArrayList list2 = new ArrayList();
list2.Add("tt");
list2.Add("ttt");
aList.InsertRange(2,list2);
结果为a b tt ttt c d e
四.删除
a) public virtual void Remove(object obj);
从 ArrayList 中移除特定对象的第一个匹配项,注意是第一个
ArrayList aList = new ArrayList();
aList.Add("a");
| 对此文章发表了评论 |

