【发布时间】:2011-10-30 11:10:11
【问题描述】:
我只是在互联网上搜索各种 .NET 集合的优缺点。我发现了以下几点
- 在查找值的上下文中,字典比 List 更快。
- HashSet 在查找值的上下文中比 List 更快。
- 在查找值的上下文中,字典比 Hashtable 更快。它们都不能保证保持项目的顺序。
- 我读到 Hashset 是 .NET 中的禁食集合
所以我得出以下 .NET 集合的排序顺序
- 哈希集
- 字典
- 哈希表
- 列表
- 数组列表
对于上述排序顺序,我使用了以下链接
- What .NET collection provides the fastest search
- http://cidamon.com/blog/solution/27/dictionary-hashtable-and-hashset
- http://www.dotnetperls.com/dictionary-time
- c# When should I use List and when should I use arraylist?
- http://www.dotnetperls.com/hashtable
- .NET HashTable Vs Dictionary - Can the Dictionary be as fast?
- http://www.codeproject.com/Answers/197792/Hashtable-and-List-in-Csharp.aspx#answer1
除了上述问题之外,我还发现了一些我想分享的有用链接
- What is the Generic version of a Hashtable?
- Why is Dictionary preferred over hashtable?
- Silverlight and ArrayList
上述排序顺序是否正确?如果不能,请重新安排一下吗?如果有人可以在上述列表的排序顺序中添加更多集合,我们将不胜感激。
【问题讨论】:
-
Hashtable和Dictionary或多或少是等价的,后者是通用的,如Why Dictionary is preferred over hashtable in C#? 中所述。Dictionary不保留其元素的顺序:其 MSDN page 声明“返回项目的顺序未定义。”。
标签: c# .net generics collections