开发者

Can you provide. NET Collection's sorted order list on basis of lookup time?

I am just searching on internet about the advantages and disadvantages of various collections of the .NET. I found the following points

  1. Dictionary is faster than List in the context of lookup for value.
  2. HashSet is faster than List in the context of lookup for value.
  3. Dictionary is faster than Hashtable in the context of lookup for value. None of them guarantee preserving the order of items.
  4. I read that Hashset is fasted collections in .NET

So I come to the following sorted order for the .NET Collections

  1. Hashset
  2. Dictionary
  3. Hashtable
  4. List
  5. ArrayList

For the above sorted order I have used the following links

  • What .NET collection provides the fastes开发者_Go百科t 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

And besides the above question I found some useful links which I want to share

  • What is the Generic version of a Hashtable?
  • Why is Dictionary preferred over hashtable?
  • Silverlight and ArrayList

Is the above sorted order is in correct order ? If not can you please rearrange it ? If anyone can add some more collections into the sorted order of the above list then it would be appreciated.


I think this article can be useful C#/.NET Fundamentals: Choosing the Right Collection Class


It depends on how you perform the lookup. That's one of the reasons why there's so many different collections. Another would be the characteristics of insert operations.

all collections serve a specific purpose. If you have a lookup key then Dictionaray<Tkey,Telement> is faster than searching a List<T> or a Hashset<T> (unless the object is the key). If you have an index List<T> is faster than Dictionary and array is even faster.

If the lookup needs to find all objects that full fill a given requirement. E.g all ints in a collection of ints where 10

So there's no set order when it comes to lookup performance. It depends on the characteristics of the lookup.

And the lookup performance only tells part of the story. The set of characteristics must be analysed as a hole to find the collection for a given task.

  • Are you going to have a lot of inserts
  • Hows lookup performed
  • Is sorting required

are some that spring to mind


SortedDictionary can be added as well in the list as it preserves elements in the order .

Thanks

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜