Thursday, May 29, 2014

How to sort on "List of objects" in VB.net?

Simple solution is below:
 
Public Class History
        Property OldValue As String
        Property NewValue As String
        Property UpdatedOn As DateTime
        Property ByWhom As String
End Class

Dim lstHistory As New List(of History)
lstHistory.Add(new History.....) 'And you have added few history objects in it.

Now we will sort it on "UpdatedOn" property.
For Ascending:
lstHistory.Sort(Function(x, y) x.UpdatedOn.CompareTo(y.UpdatedOn))

For Descending:
lstHistory.Sort(Function(x, y) y.UpdatedOn.CompareTo(x.UpdatedOn))

No comments:

Post a Comment

React-select is very slow on larger list - Found solution - using react-window

 I had more than 4000 items in searchable dropdownlist. I have used react-select but it was very slow. finally I found complete solution to ...