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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// {
using System;
using System.Collections.Generic;
using System.Linq;
namespace Answer
{
public class FilterPeopleWithLinq
{
// }
public IEnumerable<Person> KeepAdults(IEnumerable<Person> people)
{
return people.Where(p => p.Age >= 30);
}
// {
}
}
// }
Press desired key combination and then press ENTER.
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content