G
Guest
Hi,
I tried to use the Sort() function of my ArrayList object to sort a list of
the following structures:
Public Structure myData
a as Long
b as Short
End Structure
Therefore, I wrote the following Comparer:
Public Class MyComparer
Implements IComparer
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements System.Collections.IComparer.Compare
Dim one, two myData
one = CType(x, myData)
two = CType(y, myData)
Return Decimal.Compare(one.a, two.a) 'a is the interesting value
End Function
End Class
Now, when I call the sort function like that:
Dim x as new ArrayList
[...] Fill the arraylist
x.Sort(New MyComparer)
The values are sorted, beginning with the lowest value of 'a' at first
position and so on. What I'd really want is the biggest value at first
position...how could I do that?
Thanks,
Peter
I tried to use the Sort() function of my ArrayList object to sort a list of
the following structures:
Public Structure myData
a as Long
b as Short
End Structure
Therefore, I wrote the following Comparer:
Public Class MyComparer
Implements IComparer
Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer
Implements System.Collections.IComparer.Compare
Dim one, two myData
one = CType(x, myData)
two = CType(y, myData)
Return Decimal.Compare(one.a, two.a) 'a is the interesting value
End Function
End Class
Now, when I call the sort function like that:
Dim x as new ArrayList
[...] Fill the arraylist
x.Sort(New MyComparer)
The values are sorted, beginning with the lowest value of 'a' at first
position and so on. What I'd really want is the biggest value at first
position...how could I do that?
Thanks,
Peter