// Only print items less than 10.
IEnumerable subset = from i in numbers where i < 10 select i;
foreach (int i in subset)
Console.WriteLine("Item: {0}", i);
ReflectOverQueryResults(subset);
}
In this case, the subset variable is obtained (under the covers) by calling the System.Linq.
Enumerable.Where method, passing in a compiler-generated anonymous method as the second
parameter. Here is the crux of the internal definition of the subset variable generated by the com-
piler (assume the anonymous method has been named 9__CachedAnonymousMethodDelegate8):
// The following LINQ query expression:
//
// IEnumerable subset = from i in numbers where i < 10 select i;
//
// Is transformed into a call to the Enumerable.Where() method:
//
IEnumerable subset = Enumerable.Where(numbers,
Program.<>9__CachedAnonymousMethodDelegate8);
Do'stlaringiz bilan baham: |