Is there a SortedList<T> class in .net ? (not SortedList<Key,Value> which is actually a kind of Sort

Posted by Brann on Stack Overflow See other posts from Stack Overflow or by Brann
Published on 2008-12-23T19:22:29Z Indexed on 2010/05/09 1:48 UTC
Read the original article Hit count: 288

Filed under:
|
|
|

I need to sort some objects according to their contents (in fact according to one of their properties, which is NOT the key and may be duplicated between different objects)

.net provides two classes (SortedDictionnary and SortedList), and both are some kind of Dictionaries. The only difference (AFAIK) is that SortedDictionnary uses a binary tree to maintain its state whereas SortedList does not and is accessible via an index.

I could achieve what I want using a List, and then using its Sort() method with a custom implementation of IComparer, but it wouldn't be time-efficient as I would sort the whole List each time I insert a new object, whereas a good SortedList would just insert the item at the right position.

What I need is a SortedList class with a RefreshPosition(int index) to move only the changed (or inserted) object rather than resorting the whole list each time an object inside changes.

Am I missing something obvious ?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET