The Role of Differed Execution
Another important point regarding LINQ query expressions is that they are not actually evaluated
until you iterate over their contents. Formally speaking, this is termed differed execution. The bene-
fit of this approach is that you are able to apply the same LINQ query multiple times to the same
container, and rest assured you are obtaining the latest and greatest results. Consider the following
update to the QueryOverInts() method:
static void QueryOverInts()
{
int[] numbers = { 10, 20, 30, 40, 1, 2, 3, 8 };
C H A P T E R 1 4
■
A N I N T R O D U C T I O N TO L I N Q
454
8849CH14.qxd 9/26/07 12:30 PM Page 454
// Get numbers less than ten.
var subset = from i in numbers where i < 10 select i;
Do'stlaringiz bilan baham: |