Advertisement
Beginner C#, LINQ

What is LINQ and what is deferred execution?

Short answer

LINQ queries collections and data sources uniformly. Most operators are lazy: the query executes when enumerated (foreach/ToList), so it reflects the latest data.

Save C# mock interview
Advertisement
AModel answer
LINQ queries collections and data sources uniformly. Most operators are lazy: the query executes when enumerated (foreach/ToList), so it reflects the latest data.
var q = nums.Where(n => n > 2); // not run yet
nums.Add(5);
foreach (var n in q) {}          // runs now, sees 5
Real-world example
Building a filter then materialising it only after paging parameters are known.