A deferred execution query is reevaluated when you reenumerate: : Deferred Query « LINQ « C# / C Sharp






A deferred execution query is reevaluated when you reenumerate:

 

using System;
using System.Collections.Generic;
using System.Linq;
public class MainClass {
    public static void Main() {

        var numbers = new List<int>() { 1, 2 };

        IEnumerable<int> query = numbers.Select(n => n * 10);
        foreach (int n in query) Console.Write(n + "|"); 

        numbers.Clear();
        foreach (int n in query) Console.Write(n + "|"); 

    }
}

 








Related examples in the same category

1.Deferred Query Execution: shows how query execution is deferred until the query is enumerated at a foreach statement.
2.How queries can be executed immediately with operators such as ToList().
3.Shows how queries can be reused
4.Deferred Query Execution
5.Immediate Query Execution
6.most query operators is that they execute not when constructed, but when enumerated