1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| var numbers = new List<int>(); numbers.Add (1);
IEnumerable<int> query = numbers.Select (n => n * 10);
numbers.Add (2);
query.Dump ("Notice both elements are returned in the result set");
numbers.Add (3);
query.Dump();
var numbers = new List<int>() { 1, 2 };
List<int> timesTen = numbers .Select (n => n * 10) .ToList();
numbers.Clear(); timesTen.Count.Dump ("Still two elements present");
int[] numbers = { 1, 2 };
int factor = 10; IEnumerable<int> query = numbers.Select (n => n * factor);
factor = 20;
query.Dump ("Notice both numbers are multiplied by 20, not 10");
|