OrderedDictionary、ListDictionary 和 HybridDictionary 需要什么?
当三种不同的字典(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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了补充凯尔的答案:
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)
简而言之:
字典< /code>
- 嗯,一本字典。
ListDictionary
- 用于小型集合,通常少于 10 个项目HybridDictionary
- 当集合大小未知时使用(根据集合的大小切换实现)OrderedDictionary
- OrderedDictionary 的元素不按键排序,与SortedDictionary
类。您可以通过键或索引访问元素。In a nutshell:
Dictionary
- Well, a dictionary.ListDictionary
- Used for small collections, typically less than 10 itemsHybridDictionary
- 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 aSortedDictionary<TKey, TValue>
class. You can access elements either by the key or by the index.