C# 中的集合(Array/ArrayList/List<T>/HashTable/Dictionary)
int [] numbers = new int[5]; // 长度为5,元素类型为 int。 不一样的格式:
names.GetLength(0); // 得到二维数组的横向长度数组 names.GetLength(1); // 得到二维数组的纵向长度。post |
|
System.Collections.ArrayListspa ArrayList al = new ArrayList();htm al.Add(5);blog al.Add("Hello Tom");get |
System.Collections.Generic.List<T>string List<int> intList = new List<int>();io intList.Add(500); intList.AddRange(new int[]{1,100}; intList.Insert(1, 1000); cw(intList.Contains(100)); cw(intList.indexOf(10)); |
System.Collections.HashTable HashTable ht = new HashTable(); ht.Add("name", "Tom"); ht.Add("age", 18); |
System.Collections.Generic.Dictionary<TKey, TValue> Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("name", "Tom"); dic.Add("age", "eighteen"); |
哈 竟然有人留言了。
简单说一下区别吧。
一、数组(Array)和 其他四个的区别是【类型指定】【长度固定】,其他四个长度均可以不固定(也能够指定长度)。
二、ArrayList 和 List<T> 的区别是 List<T> 是【类型指定】的。
三、HashTable 和 Dictionary<Tkey, Tvalue> 的 区别和 2 中的同样。后者是【类型指定】的。