✅ Deferred Execution or Forcing Immediate Execution
So I was reading the documentation on LINQ and I came across the two concepts i wrote in the title, now lets look at:
Now its pretty clear its deferred execution, we declare the query but its actually executed when the
Is considered Immediate execution, it still declares it and then triggers the query, in this case a
This though:
Calling
Now its pretty clear its deferred execution, we declare the query but its actually executed when the
foreach is called. What I dont understand is whyIs considered Immediate execution, it still declares it and then triggers the query, in this case a
foreach internally but conceptually this is pretty much the same.This though:
Calling
.ToList or To.Array makes sense, you'd be executing the query in place and returning the result of the execution rather than saving the query to be executed later. Am I misinterpreting the documentation?