Demonstrate that most query operators are executed when constructed, but when enumerated in CSharp
Description
The following code shows how to demonstrate that most query operators are executed when constructed, but when enumerated.
Example
using System;/*w w w . ja va 2s .com*/
using System.Collections.Generic;
using System.Linq;
public class MainClass {
public static void Main() {
var numbers = new List<int>();
numbers.Add(1);
IEnumerable<int> query = numbers.Select(n => n * 10);
numbers.Add(2);
foreach (int n in query)
Console.Write(n + "|");
}
}
The code above generates the following result.