Home All Groups Group Topic Archive Search About
Author
8 May 2006 7:55 PM
PJ6
I have a Collections.Generic.Dictionary(Of Integer, Integer). I want to sort
its contents based on the keys.

Right now the only way I can think of doing this is manually creating a
KeyValuePair array from its contents, sorting it, and then clearing out the
contents and adding them all back in order.

Should I use SortedList instead? Or would that be worse for performance
since it re-sorts on every item add?

Paul

Author
8 May 2006 10:52 PM
Bob Lehmann
>> Should I use SortedList instead? Or would that be worse for performance
since it re-sorts on every item add?

What results did your perf testing produce when you compared them?

Bob Lehmann


Show quoteHide quote
"PJ6" <no***@nowhere.net> wrote in message
news:u3VMjltcGHA.3840@TK2MSFTNGP04.phx.gbl...
> I have a Collections.Generic.Dictionary(Of Integer, Integer). I want to
sort
> its contents based on the keys.
>
> Right now the only way I can think of doing this is manually creating a
> KeyValuePair array from its contents, sorting it, and then clearing out
the
> contents and adding them all back in order.
>
> Should I use SortedList instead? Or would that be worse for performance
> since it re-sorts on every item add?
>
> Paul
>
>
Author
9 May 2006 1:57 PM
PJ6
Fine I'll perf test

Show quoteHide quote
"Bob Lehmann" <nospam@dontbotherme.zzz> wrote in message
news:%23kjYuHvcGHA.1272@TK2MSFTNGP03.phx.gbl...
>>> Should I use SortedList instead? Or would that be worse for performance
> since it re-sorts on every item add?
>
> What results did your perf testing produce when you compared them?
>
> Bob Lehmann
>
>
> "PJ6" <no***@nowhere.net> wrote in message
> news:u3VMjltcGHA.3840@TK2MSFTNGP04.phx.gbl...
>> I have a Collections.Generic.Dictionary(Of Integer, Integer). I want to
> sort
>> its contents based on the keys.
>>
>> Right now the only way I can think of doing this is manually creating a
>> KeyValuePair array from its contents, sorting it, and then clearing out
> the
>> contents and adding them all back in order.
>>
>> Should I use SortedList instead? Or would that be worse for performance
>> since it re-sorts on every item add?
>>
>> Paul
>>
>>
>
>
Author
8 May 2006 10:57 PM
Mattias Sjögren
>I have a Collections.Generic.Dictionary(Of Integer, Integer). I want to sort
>its contents based on the keys.

Have you considered the SortedDictionary(Of TKey, TValue) class?


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.