C# 有哪些集合

队列【Queue】

//队列:先进先出
/*
 *增加元素到队列结尾处
 *移除队列开始处
 */
Queue queue=new Queue();
queue.Enqueue(Object);
queue.Dequeue();

堆栈【stack】

//堆栈:先进后出
/*增加元素到堆栈顶部
 *移除堆栈顶部元素
 */
Stack stack=new Stack();
stack.Push(Object);
stack.Pop();//获取并移除顶部对象
stack.Peek();//获取不移除顶部对象

键值对:Dictionary,HashTable(Dic 自定义类型,HashTable 装Object),Hashmap(java键值对集合)。

【Dictionary】

Dictionary<int,int> dictionary=new Dictionary<int,int>();

【HashTable】

HashTable hashtable=new HashTable();
hashtable.Add(Object,Object);

集合与数组:Array,ArrayList,Collection,List,HashSet,SortSet,SortedList,SortedDictionary,LinkedList

【Array】 固定大小数组   new Array[2];

【ArrayList】 可变大小数组  new ArrayList();

【Collection】集合(实体) new Collection<T>();

【List】泛型集合,拥有很多扩展方法  new List<T>();

【HashSet】非重复集合  new HashSet<T>();

【SortSet】有顺序集合   new SortSet<T>();

【SortedList】有序键值对集合:插入删除慢,内存小,适用已排序的键值对集合转换  new SortedList<key,value>();

【SortedDictionary】有序键值对集合:插入删除快,内存大,使用对键值对频繁操作  new SortedDictionary<key,value>();

【LinkedList】双向链表  new LinkedList<T>();

猜你喜欢

转载自www.cnblogs.com/codedisco/p/12568374.html