LINQ Interview Question #78

Which LINQ operations cause immediate execution?

Deferred Execution, Immediate Execution & Query Behavior Mid-Level Intermediate

Quick Interview Answer

Operators that produce a scalar value or materialize a collection execute the source immediately. Common examples include ToList, ToArray, ToDictionary, Count, LongCount, Any, All, First, Single, Sum, Average, Min, and Max.

Detailed Explanation

Operators that produce a scalar value or materialize a collection execute the source immediately. Common examples include ToList, ToArray, ToDictionary, Count, LongCount, Any, All, First, Single, Sum, Average, Min, and Max.

For IQueryable providers, calling an execution operator normally causes the provider to translate and execute the query.

Code Example

var list = query.ToList();
var array = query.ToArray();

int count = query.Count();
bool exists = query.Any();