C#集合u

List<T>  列表(动态数组),相当于C++的 vector

Queue<T>  队列,先进先出

Stack<T>  栈,先进后出

LinkedList<T>  双向链表,相当于C++中的list

SortedList<Tkey, TValue>  有序列表,相当于C++中的map

Dictionary<TKey, TValue>  字典,相当于C++中的 unordered_map

LookUp<TKey, TElement>  复合数据结构,一个键对应一个列表,相当于C++中的 std::unordered_map<T, std::vector<T>>

SortedDictionary<TKey, TValue>  有序字典,相当于C++中的 map

HashSet<T>  不重复的无序列表

SortedSet<T>  不重复的有序列表

BitArray

BitVector32

ImmutableArray<T>  不变的集合

多个并发集合  略

Hashtable  

 

 

非泛型集合:

Hashtable  每个元素都是一个存储在 DictionaryEntry 对象中的键/值对,其中键和值的类型可以是任意类型,通过 Add 方法添加键值对时,如果键已存在,则会抛出 System.ArgumentException 异常。

using System;
using System.Collections;

class Pet
{
    public Pet(int id) { this.id = id; }
    public int id;
}
class Program
{
    static void Main(string[] args)
    {
        Hashtable ht = new Hashtable();
        ht.Add("1", 1);
        ht.Add(1, "1");
        ht.Add(3.14, "3.14");
        //ht.Add("1", "a");     //抛出 System.ArgumentException 异常
        Pet pet = new Pet(3);
        ht.Add(pet, "1");
        foreach (DictionaryEntry item in ht)
        {
            Console.WriteLine(item.Key);
        }
    }
}

 HashTable数据结构存在问题:空间利用率偏低、受填充因子影响大、扩容时所有的数据需要重新进行散列计算。虽然Hash具有O(1)的数据检索效率,但它空间开销却通常很大,是以空间换取时间。所以Hashtable适用于读取操作频繁,写入操作很少的操作类型。

http://www.cnblogs.com/moozi/archive/2010/05/23/1741980.html

posted @ 2015-10-31 22:24  轻典  阅读(436)  评论(0编辑  收藏  举报