开发者

SortedList<K,V> vs SortedDictionary<K,V> vs Dictionary<K,V> [duplicate]

This question already has answers here: SortedList<>, SortedDictionary<> and Dictionary<> (6 answers) Closed 9 years ago.

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 spe开发者_高级运维ed of insertion and removal

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


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜