3 ms·
IEnumerable implicitly offers early termination. LINQ expressions are always implicit by default, so .Select(...).Take(n) will stop after taking N items. It's j
by kevingadd 7y ago
IEnumerable implicitly offers early termination. LINQ expressions are always implicit by default, so .Select(...).Take(n) will stop after taking N items. It's just like a foreach loop (same interface/API).
For the same reason, if you 'foreach' over the result of a linq query multiple times, it will evaluate the whole sequence again, which often isn't what you want - so people tend to call .ToArray() or .ToList() at the end to fully evaluate it once.
- jeswin 7y ago> IEnumerable implicitly offers early termination. LINQ expressions are always implicit by default, so .Select(...).Take(n) will stop after taking N items. My bad, indeed it does! (Embarassing, my job used to be working on LINQ-based ORM libs. Though more than a decade back.)