OrderedDictionary、ListDictionary 和 HybridDictionary 需要什么?

发布于 2024-10-10 15:39:30 字数 141 浏览 2 评论 0原文

当三种不同的字典(OrderedDictionary、ListDictionary 和 HybridDictionary)都执行相似的功能时,它们的需求是什么?

它们都没有排序,并且可以通过所有集合中的键来检索集合的元素。那么,三个不同类的目的是什么?

What is the need of three different dictionaries- OrderedDictionary,ListDictionary and HybridDictionary when all of them perform similar functions?

None of them is sorted, and elements of the collection can be retrieved by key in all of them. So, what is the purpose of three different classes?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空袭的梦i 2024-10-17 15:39:31

为了补充凯尔的答案:

OrderedDictionary 允许通过键和索引检索(它内部使用哈希表和数组),但每个项目的开销更大

ListDictionary 有一个链表作为其内部结构,它对于通过键插入和检索表现不佳但保留原始插入顺序

HybridDictionary 是一个 ListDictionary 如果字典不包含很多项目,并且如果项目数量达到特定限制则转换为 Hashtable (我个人认为你应该使用 Dictionary<,> 而不是它,因为 C# 2)

To complement Kyle's answer:

OrderedDictionary allows retrieval by key and index (it uses a hashtable and and array internally) but has a bigger overhead per item

ListDictionary has a linked list as its internal structure, it does not perform well for insertion and retrieval by key but preserves the original insert order

HybridDictionary is a ListDictionary if the dictionary does not contain many items and converts to a Hashtable if the number of items reaches a speficic limit (I personally think you should use Dictionary<,> instead of it since C#2)

紫﹏色ふ单纯 2024-10-17 15:39:30

简而言之:

In a nutshell:

  • Dictionary - Well, a dictionary.

  • ListDictionary - Used for small collections, typically less than 10 items

  • HybridDictionary - Used when the collection size is unknown (switches implementations depending on the size of the collection)

  • OrderedDictionary - The elements of an OrderedDictionary are not sorted by the key, unlike the elements of a SortedDictionary<TKey, TValue> class. You can access elements either by the key or by the index.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文