hi i was watching a video that was a simulation of where and select expression of linq to objects with extension methods and here is the code using System; using System.Collections.Generic; public static class Program { static IEnumerable<T> Where<T>(this IEnumerable<T> items, Func<T, bool> gauntlet) { Console.WriteLine("where"); foreach (T item in items) { if (gauntlet(item)) yield return item; } } static IEnumerable<R> Select<T,R>(this IEnumerable<T> items, Func<T, R> transform) { Console.WriteLine("select"); foreach (T item in items) yield return transform(item); } static void Main() { int[] stuff = { 4, 8, 1, 9 }; IEnumerable<int> result = stuff .Where(i => i < 5) .Select(i => i); IEnumerator<int> rator = result.GetEnumerator(); while (rator.MoveNext()) Console.WriteLine(rator.Current); Console.ReadLine(); } } when i run this code i get the following output select where 4 1 but i expect this output to be where select 4 1 so i bet the yield keyword is cooking something somewhere so would plz explain to me why is it happening from the end to the beginning? and not vice versa and the role of yield in there?
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)