主要区别:
一、Array的用法与数组几乎一样,可以看做是数组。在定义的时候需要指定长度;ArrayList的用法与普通集合一样,定义的时候不需要指定长度;当然,Array是抽象类,不能直接实例化,但是继承自它的子类可以实例化。
如:ArrayClass[] animalArray = new ArrayArrayClass[2]; //ArrayClass为继承自Array的类;
ArrayList animalArrayList = new ArrayList();
二、Array对象在获得元素个数时通过数组的获得方式(Length属性):animalArray.Length;ArrayList对象在获得元素个数时通过集合的获得方式(Count属性):animalArrayList.Count;
三、为Array对象赋值时,通过下标的访问方式:animalArray[1] = new Chicken("鸡鸡一");Array对象通过集合添加的方式赋值:animalArrayList.Add(new Chicken("鸡鸡二"));
概念:泛型类和泛型方法同时具备可重用性、类型安全和效率。 使用:集合和在集合上运行的方法中。
泛型数组的调用:
方法:
private List<int>GetData()
{
List<int> mylist=new List<int>();
mylist.Add(1);
mylist.Add(2);
return mylist;
}
调用:
List<int> mylist=GetData();
for(int i=0;i<mylist.Count;i++)
{
label1.text=label2.text+mylist[i].ToString();
}