How can I have a Sorted List in Descending Order?
Printable View
How can I have a Sorted List in Descending Order?
What kind of list?
Firstly, let me point out what you should have done up to now. To start with, you should have checked the appropriate radio button when creating this thread so we know what version you're using. If you're using 1.x then we know that it's a regular SortedList. If it's 2.0 then we would assume that it's a generic SortedList (i.e. SortedList<TKey, TValue>), although you really should specify because you can use either.
Before that though, you should have read the documentation for the class you're using. Assuming you are using a regular SortedList you would then have read this:You now know that if you want to use other than default sorting you have to provide an IComparer when the collection is created. That means when invoking a constructor, so you should then have read the documentation for the SortedList constructor. That would give you descriptions and examples of providing an IComparer to sort the keys.Quote:
The elements of a SortedList are sorted by the keys either according to a specific IComparer implementation specified when the SortedList is created or according to the IComparable implementation provided by the keys themselves. In either case, a SortedList does not allow duplicate keys.
You should have done all that already as a matter of course. You may still not know exactly how to declare the IComparer, but you should already know that that's what you need to do. The Help is there to help so you should ALWAYS read it first when you have a question.
Now, I'm quite prepared to provide a code example for you but not until you specify whether you're using a regular SortedList or the generic variety.
Thanks.
jmcilhinney, you are right, I should have done my homework.
I am using the regular Sorted List.
This did the trick for me.
http://www.skystonesoftware.com/temp...E-6C84E2F71E22