Deferred Query Execution : Deferred Query « LINQ « C# / C Sharp






Deferred Query Execution

 

using System;
using System.Linq;

class MainClass {
    static double Square(double n) {
        return Math.Pow(n, 2);
    }
    public static void Main() {
        int[] numbers = { 1, 2, 3 };
        var query = from n in numbers select Square(n);
        foreach (var n in query)
            Console.WriteLine(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.Immediate Query Execution
5.A deferred execution query is reevaluated when you reenumerate:
6.most query operators is that they execute not when constructed, but when enumerated