1.数组集合
其实,在数组的一节里面已经包含了这个概念了。其实数组集合就是 new int[2];
官方参考地址:http://msdn.microsoft.com/zh-cn/library/57yac89c(VS.80).aspx
2.ArrayList
ArrayList跟数组(Array)的区别:http://msdn.microsoft.com/zh-cn/library/41107z8a(VS.80).aspx
实例:

c# 集合类:ArrayList,StringCollection,Hashtable,Listc# 集合类:ArrayList,StringCollection,Hashtable,Listusing }

这里同时要提到StringCollection,其实这个跟ArrayList没啥区别,只不过StringCollection只能接收字符类型的东西。
官方地址:http://msdn.microsoft.com/zh-cn/library/system.collections.specialized.stringcollection(VS.80).aspx

3.List<T> ,这个我想才是我们最常用的。
官方参考地址:http://msdn.microsoft.com/zh-cn/library/6sh2ey19(VS.80).aspx
这个其实就是泛型结合数组的例子。

c# 集合类:ArrayList,StringCollection,Hashtable,Listc# 集合类:ArrayList,StringCollection,Hashtable,Listusing }


c# 集合类:ArrayList,StringCollection,Hashtable,ListArrayList obAppleArrayList = new ArrayList();
c# 集合类:ArrayList,StringCollection,Hashtable,List            obAppleArrayList.Add(objApple1);
c# 集合类:ArrayList,StringCollection,Hashtable,List            obAppleArrayList.Add(objApple2);
c# 集合类:ArrayList,StringCollection,Hashtable,List            obAppleArrayList.Add(objApple2);

我们不用的ArrayList的目的是保证类型安全。因为这个时候,你还可以obAppleArrayList.Add("string");,obAppleArrayList.Add("heihei");,这样obAppleArrayList的元素就不是单纯的Apple类了。
我们最常用的也是List<T>.

4.Hashtable,
官方地址:http://msdn.microsoft.com/zh-cn/library/system.collections.hashtable(VS.80).aspx
实例:

c# 集合类:ArrayList,StringCollection,Hashtable,Listc# 集合类:ArrayList,StringCollection,Hashtable,Listusing }

相关文章: