Invert an Arraylist.Sort()

D

Derek Martin

Hi List, I have an arraylist of objects. I have created my own IComparable
in the object to return the sort on datetime. This works great! Now, I'd
like to invert the sort. Currently, it gives me 4/1/05 before 4/5/05
(good), but I'd like to have 4/5/05 before 4/1/05 (better!) for my
application.

Public Function CompareTo(ByVal obj As Object) As Integer Implements + _
System.IComparable.CompareTo
If TypeOf obj Is glcobject Then
Dim tmp As glcobject = DirectCast(obj, glcobject)
Return m_datetime.CompareTo(tmp.m_datetime)
End If
End Function

???

Thanks!
Derek
 
M

Marina

Maybe create a property which tells your object which way to sort. Then in
CompareTo look at that property, and return the appropriate result.
 
G

Guest

If m_ascending Then
If Not v_CaseSensitive Then Return New
CaseInsensitiveComparer().Compare(x, y) Else Return New
Comparer(ci).Compare(x, y)
Else
If Not v_CaseSensitive Then Return New
CaseInsensitiveComparer().Compare(y, x) Else Return New
Comparer(ci).Compare(y, x)
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top