Tutorial by Examples

Some LINQ methods return a query object. This object does not hold the results of the query; instead, it has all the information needed to generate those results: var list = new List<int>() {1, 2, 3, 4, 5}; var query = list.Select(x => { Console.Write($"{x} "); return ...
Of the LINQ methods which use deferred execution, some require a single value to be evaluated at a time. The following code: var lst = new List<int>() {3, 5, 1, 2}; var streamingQuery = lst.Select(x => { Console.WriteLine(x); return x; }); foreach (var i in streamingQuery) { ...
Deferred execution enables combining different operations to build the final query, before evaluating the values: var list = new List<int>() {1,1,2,3,5,8}; var query = list.Select(x => x + 1); If we execute the query at this point: foreach (var x in query) { Console.Write($"...
With deferred execution, if the data to be queried is changed, the query object uses the data at the time of execution, not at the time of definition. var data = new List<int>() {2, 4, 6, 8}; var query = data.Select(x => x * x); If we execute the query at this point with an immediate m...

Page 1 of 1