Question

i have a list of my g class

Public Class g
    Public x as Decimal
    Public y As Decimal
End Class

Dim MyQuery As List(Of g) = ...

which i try to sort like

Dim sorted As List(Of g) = MyQuery.OrderBy(Function(x) x.y).ThenBy(Function(x) x.x).ToList()

Unfortunately i get the following error

At least one object must implement IComparable.

What am i doing wrong here? When i try to sort by one property i get no errors

Dim sorted As List(Of g) = MyQuery.OrderBy(Function(x) x.y).ToList()

Was it helpful?

Solution

The code you provided in your question works as is. Your original code most likely doesn't use decimal for the properties but some other type that doesn't implement IComparable, resulting in the exception you get.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top