Sort a List of Object in VB.NET

后端 未结 4 663
刺人心
刺人心 2020-11-30 03:31

I have a list of passengers(object) where it has a differents properties..

passenger.name
passenger.age
passenger.surname

And I want to sor

4条回答
  •  时光取名叫无心
    2020-11-30 04:22

    To sort by a property in the object, you have to specify a comparer or a method to get that property.

    Using the List.Sort method:

    theList.Sort(Function(x, y) x.age.CompareTo(y.age))
    

    Using the OrderBy extension method:

    theList = theList.OrderBy(Function(x) x.age).ToList()
    

提交回复
热议问题