Tutorial by Examples

Concatenation refers to the operation of appending one sequence to another. Concat Concatenates two sequences to form one sequence. Method Syntax // Concat var numbers1 = new int[] { 1, 2, 3 }; var numbers2 = new int[] { 4, 5, 6 }; var numbers = numbers1.Concat(numbers2); // number...
Filtering refers to the operations of restricting the result set to contain only those elements that satisfy a specified condition. Where Selects values that are based on a predicate function. Method Syntax // Where var numbers = new int[] { 1, 2, 3, 4, 5, 6, 7, 8 }; var evens = number...
A join of two data sources is the association of objects in one data source with objects that share a common attribute in another data source. Join Joins two sequences based on key selector functions and extracts pairs of values. Method Syntax // Join class Customer { public int Id ...
Projection refers to the operations of transforming an object into a new form. Select Projects values that are based on a transform function. Method Syntax // Select var numbers = new int[] { 1, 2, 3, 4, 5 }; var strings = numbers.Select(n => n.ToString()); // strings = { "1...
A sorting operation orders the elements of a sequence based on one or more attributes. OrderBy Sorts values in ascending order. Method Syntax // OrderBy var numbers = new int[] { 5, 4, 8, 2, 7, 1, 9, 3, 6 }; var ordered = numbers.OrderBy(n => n); // ordered = { 1, 2, 3, 4, 5, 6, ...
Conversion operations change the type of input objects. AsEnumerable Returns the input typed as IEnumerable. Method Syntax // AsEnumerable int[] numbers = { 1, 2, 3, 4, 5 }; var nums = numbers.AsEnumerable(); // nums: static type is IEnumerable<int> Query Syntax // Not app...
Aggregation operations computes a single value from a collection of values. Aggregate Performs a custom aggregation operation on the values of a collection. Method Syntax // Aggregate var numbers = new int[] { 1, 2, 3, 4, 5 }; var product = numbers.Aggregate(1, (acc, n) => acc * n);...
Quantifier operations return a Boolean value that indicates whether some or all of the elements in a sequence satisfy a condition. All Determines whether all the elements in a sequence satisfy a condition. Method Syntax // All var numbers = new int[] { 1, 2, 3, 4, 5 }; bool areLessThan...
Grouping refers to the operations of putting data into groups so that the elements in each group share a common attribute. GroupBy Groups elements that share a common attribute. Method Syntax // GroupBy class Order { public string Customer { get; set; } public string Descriptio...
Partitioning refers to the operations of dividing an input sequence into two sections, without rearranging the elements, and then returning one of the sections. Skip Skips elements up to a specified position in a sequence. Method Syntax // Skip var numbers = new int[] { 1, 2, 3, 4, 5 }; ...
Generation refers to creating a new sequence of values. DefaultIfEmpty Replaces an empty collection with a default valued singleton collection. Method Syntax // DefaultIfEmpty var nums = new int[0]; var numbers = nums.DefaultIfEmpty(); // numbers = { 0 } Query Syntax // Not appl...
Set operations refer to query operations that produce a result set that is based on the presence or absence of equivalent elements within the same or separate collections (or sets). Distinct Removes duplicate values from a collection. Method Syntax // Distinct var numbers = new int[] { 1,...
Two sequences whose corresponding elements are equal and which have the same number of elements are considered equal. SequenceEqual Determines whether two sequences are equal by comparing elements in a pair-wise manner. Method Syntax // SequenceEqual var numbers1 = new int[] { 1, 2, 3, 4,...
Element operations return a single, specific element from a sequence. ElementAt Returns the element at a specified index in a collection. Method Syntax // ElementAt var strings = new string[] { "zero", "one", "two", "three" }; var str = strings.E...

Page 1 of 1