让我们来看看DotNet中System.Collections名字空间包含的可变数组对象.
1)ArrayList(数组列表)
      本质上ArrayList对象就是一个可变长的数组,可以根据需要添加元素.使用ArrayList的方法可以向数组列表中添加元素,或取出,修改某个元素.
      .Add()方法
     

DotNet中的集合对象(1): ArrayListusing System;
DotNet中的集合对象(1): ArrayList
using System.Collections;
DotNet中的集合对象(1): ArrayList
class TestArrayList
}
    ArrayList有一个Count属性,可以确定它所包含的实际元素数目.
    .Clear                                            删除ArrayList中的内容
DotNet中的集合对象(1): ArrayListusing System;
DotNet中的集合对象(1): ArrayList
using System.Collections;
DotNet中的集合对象(1): ArrayList
class TestArrayList
}
    ArrayList中取出的对象都是object类型,使用前要将其转换成合适的类型.
DotNet中的集合对象(1): ArrayListArrayList theArrayList = new ArrayList();
DotNet中的集合对象(1): ArrayListtheArrayList.Add(
"1");
DotNet中的集合对象(1): ArrayListtheArrayList.Add(
"2");
DotNet中的集合对象(1): ArrayList
string s = (string)theArrayList[0];
DotNet中的集合对象(1): ArrayList
string s1 = (string)theArrayList[1];
DotNet中的集合对象(1): ArrayList
DotNet中的集合对象(1): ArrayList
     .Contains()    如果ArrayList中包含参数提供的对象,则返回true,否则返回false
    
DotNet中的集合对象(1): ArrayListusing System;
DotNet中的集合对象(1): ArrayList
using System.Collections;
DotNet中的集合对象(1): ArrayList
class TestArrayList
}

    CopyTo()    将ArrayList 全部内容拷贝到一个一维数组中
DotNet中的集合对象(1): ArrayListusing System;
DotNet中的集合对象(1): ArrayList
using System.Collections;
DotNet中的集合对象(1): ArrayList
class TestArrayList
}

     IndexOf()
DotNet中的集合对象(1): ArrayListusing System;
DotNet中的集合对象(1): ArrayList
using System.Collections;
DotNet中的集合对象(1): ArrayList
class TestArrayList
}
   Insert () 将元素插入到ArrayList指定的位置
 

相关文章: