hello,
as i started up with linq, i wrote the following simple query:
String[] alphabet = {"alpha", "beta", "gamma", "delta", "epsilon" };
var myQuery = from letter in alphabet
where letter.Length > 4
select letter;
foreach (var letter in myQuery)
//code to display letter
what i don't understand is the following:
when in debugging mode, after stepping over the statement var myQuery = ... ;, the Locals Windows shows in the Results View corresponding to myQuery, the expected result for the query (the IEnumerable collection alpha, gamma, delta and epsilon).
so the result of this query is computed before entering the foreach loop. then why, inside the execution of the foreach loop, does the variable letter gets first the value "alpha", then the execution goes to the where keyword in the query, to check the filtering predicate and if the predicate is verified it goes back to the foreach, displays the val and then variable letter gets value "beta" and the same execution pattern follows?
thank you