Can you reverse the sort order of a sortedlist class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am using the sortedlist class but would like the order of the class to be
reversed. I know i could loop through the sortedlist class backwards using
the index but i would rather have a method on my class which has a private
instance of the sortedlist class and be able to specify the order that the
sortedlist class is sorted by. Is this possibe? I know an alternative is to
use the arraylist class where i can reverse order but this doesn't allow me
to access the objects in the arraylist by a key which the sortedlist class
does?

ANy help would be excellent.

THanks
T
 
T said:
Hi,

I am using the sortedlist class but would like the order of the class to be
reversed. I know i could loop through the sortedlist class backwards using
the index but i would rather have a method on my class which has a private
instance of the sortedlist class and be able to specify the order that the
sortedlist class is sorted by. Is this possibe? I know an alternative is to
use the arraylist class where i can reverse order but this doesn't allow me
to access the objects in the arraylist by a key which the sortedlist class
does?

ANy help would be excellent.

You can do most of what you want by using the IComparer interface. When
you create the SortedList, you can pass an instance of an IComparer to
the constructor. This instance allows you to specify how to compare any
two items in the list. If you want to reverse your sort order, write a
new IComparer-derived class that sorts items in the opposite order.

Let me know if you need code that shows this.

bab

--
Brian Button (e-mail address removed)
Principal Consultant http://www.agilesolutionsgroup.com
Agile Solutions Group http://dotnetjunkies.com/weblog/oneagilecoder
St. Louis, MO 636.399.3146

Extreme Programming in St Louis - http://groups.yahoo.com/group/xpstl
 
Back
Top