When to use a SortedList over a SortedDictionary?

后端 未结 6 506
梦毁少年i
梦毁少年i 2020-11-29 01:50

This may appear to be a duplicate of this question, which asks \"What’s the difference between SortedList and SortedDictionary?\" Unfortunately, the answers do nothing more

6条回答
  •  天涯浪人
    2020-11-29 02:07

    That's all there is to it. Retrieval of keys is comparable, but addition is much faster with Dictionaries.

    I try to use SortedList as much as possible because it allows me to iterate over the keys and value collections. This is not possible with SortedDictionary as far as I know.

    I'm not sure about this, but as far as I know Dictionaries store data in Tree structures, whereas List store data in linear arrays. That explains why insertion and removal is much faster with dictionaries, since less memory has to be shifted around. It also explains why you can iterate over SortedLists but not SortedDictionary.

提交回复
热议问题