Query with Intentional Exception Deferred Until Enumeration

image_pdfimage_print
   
 

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        string[] strings = { "one", "two", null, "three" };

        Console.WriteLine("Before Where() is called.");
        IEnumerable<string> ieStrings = strings.Where(s => s.Length == 3);
        Console.WriteLine("After Where() is called.");

        foreach (string s in ieStrings) {
            Console.WriteLine("Processing " + s);
        }

    }
}

    


This entry was posted in LINQ. Bookmark the permalink.