LINQ Interview Question #72

What does All do in LINQ?

Joins, Grouping, Set & Quantifier Operators Mid-Level Intermediate

Quick Interview Answer

All returns true when every element satisfies a predicate. It stops when it finds an element that fails the condition.

Detailed Explanation

All returns true when every element satisfies a predicate. It stops when it finds an element that fails the condition.

An important detail is that All returns true for an empty sequence because there is no element that violates the predicate.

Code Example

bool allActive = users
    .All(u => u.IsActive);

bool allPositive = numbers
    .All(n => n > 0);