zoukankan      html  css  js  c++  java
  • .net框架-字典对象 Hashtable & Dictionary<TKey,TValue> & SortedList

    字典对象:

      字典对象是表示键值对的集合

      字典对象有Hashtable(.net 1.0)及其泛型版本Dictionary<TKey,TValue>

      字典对象还包括SortedList及其泛型版本SortedList<TKey,TValue>(SortedList按键进行排序)

      字典对象实现了接口:IDictionary, ICollection, IEnumerable, ICloneable (泛型实现了IDictionary, ICollection, IEnumerable对应的泛型接口)

    IDictionary接口:

      object this[object key] {get;set;}  

      ICollection Keys {get;set;}

      ICollection Values {get;set;}

      void Add(object key, object value)

      void Remove (object key)

      object Contains(object key)

    IDictionary<TKey, TValue>接口:

      (1)与IDictionary相同的:

        TValue this[TKey] {get;set;}  

        void Add(TKey,TValue)

        .........  (其它同IDictionary接口略,其它形式均为泛型T占位符参数代替Object参数)

      (2)与IDictionary不同的:

        bool ContainsKey(TKey)

        bool TryGetValue(TKey, out TValue value)

    区别:

      Hastable 和 Dictionary<TKey,TValue>,前者是.net1.0下的字典对象,后者是前者泛型版本 ,泛型减少了装、拆箱和强制转换,效率更高

      SortedList 和 SortedList<TKey,TValue>,按键序存储的字典对象

      Hastable和SortedList,前进自然存储、后者按键序存储,故前者插入快,查找慢,后者反之。

      

    参考:

      http://www.cnblogs.com/xqhppt/archive/2011/09/15/2178101.html

  • 相关阅读:
    Codeforces Round #260 (Div. 1) A
    cdoj 1131 男神的礼物 区间dp
    bzoj2435: [Noi2011]道路修建 树上dp
    hdu 4597 Play Game 区间dp
    cdoj 31 饭卡(card) 01背包
    hdu5256 序列变换 dp LIS
    BZOJ 4027: [HEOI2015]兔子与樱花 树上dp
    Codeforces Round #202 (Div. 1) D. Turtles dp
    hdu 4114 Disney's FastPass 状压dp
    Python help() 函数
  • 原文地址:https://www.cnblogs.com/ybtools/p/6382155.html
Copyright © 2011-2022 走看看