Search code examples
c#.netdictionarygeneric-collections

SortedList<K,V> vs SortedDictionary<K,V> vs Dictionary<K,V>


I have a large collection of small objects, each has a unique string ident. I need to decide which class to use.

MSDN says about the first two

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

Since I rarely insert, mostly just retrieve it seems both are good for me. What about the plain old Dictionary?


Solution

  • Plain-old dictionary is the best option if you're not interested in sorting (since it's O(1) retrieval). If you're not going to modify the list much you should use SortedList since it uses less memory.