SortedList<>,SortedDictionary<>和Dictionary<> [英] SortedList<>, SortedDictionary<> and Dictionary<>

查看:133
本文介绍了SortedList<>,SortedDictionary<>和Dictionary<>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 SortedList< TKey,TValue> SortedDictionary< TKey,TValue> 字典< TKey,TValue> 实现相同的接口。

I find that SortedList<TKey, TValue> SortedDictionary<TKey, TValue> and Dictionary<TKey, TValue> implement the same interfaces.


  1. 我们什么时候应该选择 SortedList SortedDictionary 超过字典

  2. SortedList SortedDictionary 在应用程序?

  1. When should we opt for SortedList and SortedDictionary over Dictionary?
  2. What is the difference between SortedList and SortedDictionary in terms of application?


推荐答案


  1. 当迭代二者中的任何一个元素时,元素将被排序。

MSDN 解决了 SortedList< T,V> SortedDictionary< T,V>




SortedDictionary(TKey,TValue)泛型类是一个二元搜索
树< a>与O(log n)检索,其中n是字典
中元素的数量。在这方面,它类似于SortedList(TKey,
TValue)泛型类。这两个类有相似的对象模型,
都有O(log n)检索。两个类别的差异在于
内存使用和插入和删除速度:

The SortedDictionary(TKey, TValue) generic class is a binary search tree with O(log n) retrieval, where n is the number of elements in the dictionary. In this respect, it is similar to the SortedList(TKey, TValue) generic class. The two classes have similar object models, and both have O(log n) retrieval. Where the two classes differ is in memory use and speed of insertion and removal:

SortedList(TKey,TValue)使用的内存少于SortedDictionary(TKey,
TValue)

SortedList(TKey, TValue) uses less memory than SortedDictionary(TKey, TValue).

SortedDictionary(TKey,TValue)对未排序的数据进行更快的插入和删除
操作:O(log n)而不是O (n)for
SortedList(TKey,TValue)。

SortedDictionary(TKey, TValue) has faster insertion and removal operations for unsorted data: O(log n) as opposed to O(n) for SortedList(TKey, TValue).

如果列表从排序数据一次性填充,
SortedList(TKey, TValue)比SortedDictionary(TKey,
TValue)快。

If the list is populated all at once from sorted data, SortedList(TKey, TValue) is faster than SortedDictionary(TKey, TValue).

这篇关于SortedList&lt;&gt;,SortedDictionary&lt;&gt;和Dictionary&lt;&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆