C#的集合类型简述
1.数组
集合添加数值要用Add();
由于ArrayList无法规定进去值的类型,并且在装入值类型的时候,会有个装箱的过程,故常用List泛型集合来创建数组,比如:
List<int> a = new List<int>();
List中有增删查的功能
2.哈希表
哈希表的格式为
Hash<Key,Value>;
其中Key作索引线索,Key与Value的数值不做类型要求。
我对其理解为Hash表就是变形的数组,只不过Key的类型由int变为任意类型,Value的类型亦不做要求
3.字典
字典中则强制规定类型输入,例如:
Dictionary<string,string> d = new Dictionary<string,string>();
其中第一个数值依旧为Key,第二个为Value。
4.SortedList
这个方法的用处和它的名字一样,放置其中的一定是已经按照Key值大小排列好的数组。例如:
SortedList<int,int> s1=new SortedList<int,int>();
s1.Add(5,105);
s1.Add(2,102);
s1.Add(10,99);
当Key值要求为string时,也可以用字符串“int类型数据”,从而方便从小到大的排序。