Demonstrate that a deferred execution query is reevaluated when you reenumerate in CSharp
Description
The following code shows how to demonstrate that a deferred execution query is reevaluated when you reenumerate.
Example
using System;//from w ww . j a v a2s .c o m
using System.Collections.Generic;
using System.Linq;
public class MainClass {
public static void Main() {
var numbers = new List<int>() { 1, 2 };
IEnumerable<int> query = numbers.Select(n => n * 10);
foreach (int n in query) Console.Write(n + "|");
numbers.Clear();
foreach (int n in query) Console.Write(n + "|");
}
}
The code above generates the following result.