Use findAll and then Sort in vb.NET listOf

I am trying to get certain elements of the listOf structure with the findAll function plus the lambda function, and then sort this result and save this sorting of the elements that were saved in the list. The listOf structure has id and age, so I want to get all the elements with id = 0 and then sort the ages of this result, saving this modification in a variable.

This is what I tried, but it does not work.

list.FindAll(Function(p1) p1.id = 0).Sort(Function(p1, p2) p1.age > p2.age)
+3
source share
1 answer

, FindAll , . , , . FindAll Sort , :

list = list.FindAll(Function(p1) p1.id = 0)
list.Sort(Function(p1, p2) p1.age.CompareTo(p2.age))

Linq , Linq, . :

list = list.Where(Function(p1) p1.id = 0) _
           .OrderBy(Function(p1) p1.Age).ToList()
+4

All Articles