Get the first and second objects from a list using LINQ
- by Vahid
I have a list of Person objects. How can I get the first and second Person objects that meet a certain criteria from List<Person> People using LINQ?
Let's say here is the list I've got. How can I get the first and second persons that are over 18 that is James and Jodie.
public class Person
{
public string Name;
public int age;
}
var People = new List<Person>
{
new Person {Name = "Jack", Age = 15},
new Person {Name = "James" , Age = 19},
new Person {Name = "John" , Age = 14},
new Person {Name = "Jodie" , Age = 21},
new Person {Name = "Jessie" , Age = 19}
}