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>();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM