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.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
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.