Mega Code Archive

 
Categories / C# / LINQ
 

Query with Intentional Exception Deferred Until Enumeration

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);         }     } }