Open Source Your Knowledge, Become a Contributor
Technology knowledge has to be shared and made accessible for free. Join the movement.
Filter data with Where
We've built up our understanding of LINQ using Where(predicate)
in the last section.
You can apply Where
to restrict the result set to contain only elements that satisfy a specified condition.
Example
Return all people, who are at least 30 years old.
Where
1
11
12
13
14
15
// {
public IEnumerable<Person> KeepAdults(IEnumerable<Person> people)
{
return people.Where(p => p.Age >= 30);
}
// {
Enter to Rename, Shift+Enter to Preview
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content