linq Immediate Execution

The following sample shows how queries can be executed immediately with operators such as ToList().
public static void Immediate_Execution()
{
            // Methods like ToList() cause the query to be
            // executed immediately, caching the results.

            int[] numbers = new int[] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

            int i = 0;
            var q = (from n in numbers
                     select ++i).ToList();

            // The local variable i has already been fully
            // incremented before we iterate the results:
            foreach (var v in q)
            {
                Console.WriteLine("v = {0}, i = {1}", v, i);
            }
}
Output
linq Immediate Execution linq Immediate Execution Reviewed by Bhaumik Patel on 4:29 AM Rating: 5