GroupBy is a LINQ functionality which allows to group items from a collection based on a given key. It’s an equivalent to SQL’s GROUP BY clause. In this article we’ll show various examples of usage, starting from the simplest grouping by one key, through grouping by multiple keys, custom result selector and all of that in two variants: Lambda and Query expression.
Continue reading C# – LINQ GroupBy ExamplesCategory: LINQ
C# – LINQ Join Examples
Join is a LINQ functionality to combine two collections and produce a single result set. Connection happens by comparing items from both series. When there is a match then such pair is one of the output elements.
Continue reading C# – LINQ Join ExamplesC# – How to get unique items from list
The easiest way of getting unique items from list is LINQ’s Distinct() method. In this article you’ll see how to use it with both built-in types (like collection of integers) and custom types (like collection of complex type objects).
Continue reading C# – How to get unique items from listC# – LINQ Any Examples
Any is LINQ functionality to validate whether collection contains at least one element which meets given criteria. Continue reading C# – LINQ Any Examples
C# – LINQ First Examples
First is LINQ functionality to return first item of the collection or throw exception if such item does not exist. Continue reading C# – LINQ First Examples
C# – LINQ Take Example
Take is LINQ functionality to get given number of elements from the beginning of a collection. Below you can find out how to use it. Continue reading C# – LINQ Take Example
C# – LINQ Skip Example
Skip is LINQ functionality to filter collection by omitting given number of first elements. Below is an example how to use it. Continue reading C# – LINQ Skip Example
C# – LINQ FirstOrDefault Examples
FirstOrDefault is a LINQ functionality to return first element of the collection or default value if requested item does not exist. In case of collection of reference type objects the default is null, whilst in case of value types the default depends on the particular type (e.g. for int it is 0).
FirstOrDefault is overloaded method which can be used with either zero or one parameter. The first option just returns first element and the second one allows to define condition which needs to be met. Continue reading C# – LINQ FirstOrDefault Examples
C# – LINQ Select Examples
Select is a LINQ functionality to define a data format of the query results.
Each of below examples is presented in C# with both Lambda and Query expression. Continue reading C# – LINQ Select Examples
C# – LINQ Where Examples
Where is a LINQ functionality to filter data in a query with given criteria.
Each of below examples is presented in C# with both Lambda and Query expression. Continue reading C# – LINQ Where Examples