“EnumerableToArray” (Solution)
GetString: Foo
EnumerableToArray: Foo
GetString: Bar
EnumerableToArray: Bar
GetString: Foo
GetString: Bar
var strings = GetStringEnumerable();
will not print anything to the console. Next, in the loop
foreach (var s in strings)
Console.WriteLine("EnumerableToArray: " + s);
query execution will be performed. Moreover, first will be evaluated the first
yield
(print GetString: Foo
), next the loop body will be evaluated for the first enumerable element (print EnumerableToArray: Foo
). Next, the foreach
loop will require the second enumerable element, the second yield
will be evaluated (print GetString: Bar
), the loop body will be evaluated for the second element (print EnumerableToArray: Bar
).Next, the following line will be executed:
return strings.ToArray();
Our LINQ query will be performed again. So, the lines
GetString: Foo
and GetString: Bar
will be printed again.Last modified 4yr ago