DEV Community

Discussion on: LINQ: Beware of deferred execution

Collapse
jeikabu profile image
jeikabu

I never really thought of the re-evaluation as a problem- it's conceptually similar to a function that calls a for loop.

Honestly, I feel that calling ToList() is more suspect. Not when you actually need a list, but simply to "evaluate" an expression. Besides just extra allocations, what if the number of items is huge? We tended to treat it like a query and use first/firstordefault/any/etc. I guess it makes sense if you want to save the results for later, maybe we just didn't use linq in cases where the results were static.