LINQ Interview Question #19
What does the Where operator do?
LINQ Fundamentals, Syntax, IEnumerable & IQueryable Junior Beginner
Quick Interview Answer
Where filters a sequence by returning only elements that satisfy a predicate. It does not normally modify the original source.
Detailed Explanation
Where filters a sequence by returning only elements that satisfy a predicate. It does not normally modify the original source.
Where uses deferred execution for IEnumerable<T> and builds a larger expression for IQueryable<T>. Multiple Where calls can be composed when that improves query construction or readability.
Code Example
var adults = people
.Where(p => p.Age >= 18);
var activeAdults = people
.Where(p => p.Age >= 18)
.Where(p => p.IsActive);