zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    博客地址
    node学习2
    正则表达式总结
    Git命令操作
    IDEA快捷键
    hibernate多对多(权限管理)
    所有国家的下拉框英文全称
    所有国家的下拉框英文简写
    所有国家的下拉框中文
    poj-1248 Safecracker
  • 原文地址:https://www.cnblogs.com/tianyajuanke/p/4926382.html
Copyright © 2011-2022 走看看