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.
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 5Real-world example
Building a filter then materialising it only after paging parameters are known.