LINQ Interview Question #27
Can Where use multiple conditions?
Filtering, Projection, Ordering & Element Operators Junior Beginner
Quick Interview Answer
Yes. A single Where predicate can combine conditions with Boolean operators such as && and ||. Multiple Where calls can also be chained.
Detailed Explanation
Yes. A single Where predicate can combine conditions with Boolean operators such as && and ||. Multiple Where calls can also be chained.
Both forms can express the same logic in many cases. Separate Where calls are sometimes useful when conditions are added dynamically, while a combined predicate can be concise for fixed conditions.
Code Example
var result = products.Where(p =>
p.IsActive &&
p.Price >= 100 &&
p.CategoryId == 5);
// Also valid:
var result2 = products
.Where(p => p.IsActive)
.Where(p => p.Price >= 100);