Shows how queries can be reused : Deferred Query : LINQ C# Source Code


Custom Search

C# Source Code » LINQ » Deferred Query »

 

Shows how queries can be reused








    
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {
        int[] numbers = new int[] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
        var lowNumbers =
            from n in numbers
            where n <= 3
            select n;

        Console.WriteLine("First run numbers <= 3:");
        foreach (int n in lowNumbers) {
            Console.WriteLine(n);
        }

        for (int i = 0; i < 10; i++) {
            numbers[i] = -numbers[i];
        }

        Console.WriteLine("Second run numbers <= 3:");
        foreach (int n in lowNumbers) {
            Console.WriteLine(n);
        }
    }
}

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo LINQ
» Deferred Query