3 ms·
> But it's still just syntactic sugar, the neater code just masks the underlying code that contains the actual loops and conditionals. It seemed to me that was
by Gibbon1 7y ago
> But it's still just syntactic sugar, the neater code just masks the underlying code that contains the actual loops and conditionals.
It seemed to me that was often more performant than using a loop.
- wffurr 7y agoLinq pipelines are lazily evaluated, so you can get linear performance instead of polynomial.
- henrikschroder 7y agoIt depends on what you do, and the underlying code can be pretty smart. But it can also be pretty dumb. The main difference is that if you use .Where(P).Take(X), you're actually generating a new enumerator, a new coroutine, and that code doesn't get called until you actually enumerate it. But if you write your for/if loop, you run the code immediately, you go through the source array, run the predicate on each item, until you have your X items, and then you return a new array with those elements.