首页 > Web开发 > 详细

.net框架-字典对象 Hashtable & Dictionary<TKey,TValue> & SortedList

时间:2017-02-09 15:31:01      阅读:236      评论:0      收藏:0      [点我收藏+]

字典对象:

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

  字典对象有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

 

.net框架-字典对象 Hashtable & Dictionary<TKey,TValue> & SortedList

原文:http://www.cnblogs.com/ybtools/p/6382155.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!