Say I have a simple Linq query:
var x = words.Where(w => w.Length > 4).Select(w => w.ToUpper()).ToArray();
Will the compiler generate code that iterates over words
once, filtering and transforming as it goes, or code that generates an intermediate enumeration and then iterates over that?
What if there's an OrderBy()
:
var x = words.Where(w => w.Length > 4).OrderBy(w => w).Select(w => w.ToUpper()).ToArray();
I could see the compiler either iterating once over words, filtering and uppercasing words as it goes and merging them into an already sorted IOrderedEnumerable
, or I could see it generating an intermediate array, sorting that, and then transforming it.