Deferred Execution

Most query operators is executed not when constructed, but when enumerated.

Consider the following query:

 
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main()
    {
        var numbers = new List<int>();
        numbers.Add(1);

        IEnumerable<int> query = numbers.Select(n => n * 10);

        numbers.Add(2);

        foreach (int n in query)
            Console.Write(n + "|"); // 10|20|
    }
}

The output:


10|20|
java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.