Tags

LINQ Distinct Operator

LINQ Distinct operator is used for removing duplicates elements from the sequence (list). Distinct operator comes under Set operators category in LINQ query operators. For example, we have one collection A = { 1, 2, 3, 3, 4, 4, 5}. In this collection 3 and 4 elements are repeated two times and we have to create a new sequence which takes these duplicates only one time. So we use distinct opera...

Continue Reading

LINQ Intersect Operator

LINQ Intersect operator is used to find common elements between two sequences (collections). Intersect opertor comes under Set operators category in LINQ Query operators. For example, we have two collections A = { 1, 2, 3 } and B = { 3, 4, 5 }. Intersect operator will find common elements in both sequences. { 3 } element is common in both sequences. So Intersect operator only shows one element...

Continue Reading

LINQ Union Operator

LINQ Union operator is used for finding unique elements between two sequences (Collections). For example, suppose we have two collections A = { 1, 2, 3 }, and B = { 3, 4, 5 }. Union operator will find unique elements in both sequences. { 3 } element is available in both sequences. So union operator only takes one element in the result. C = { 1, 2, 3, 4, 5 }. Union operator is only supported...

Continue Reading

LINQ Except Operator

LINQ Except operator comes under Set operators category in LINQ. LINQ Set operators is used for compare two sequences (collections) and find common, missing and unique elements. You can find entire list of set operators here. Except operator compares two sequences (collections) classes and find those elements which are not present in second sequence. For example. suppose we have a collection A...

Continue Reading

LINQ OrderByDescending Operator

LINQ OrderByDescending operator sort the elements in a sequence in descending order. You can find LINQ sorting operators list here. Below is the syntax of OrderByDescending operator. public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector); As shown in above syntax, OrderByDesce...

Continue Reading

LINQ ThenBy Operator

LINQ ThenBy Operator is used when we want to sort the elements in a collection by using multiple properties in ascending order. This operator must use after OrderBy or OrderByDescending operator. First OrderBy operator sort the collection based on a single property and then we can use ThenBy operator to sort the collection by second property. We can use multiple ThenBy operator in a collection...

Continue Reading

LINQ OrderBy Operator

LINQ OrderBy operator comes first in LINQ Sorting Operators. OrderBy operator sort the sequence (collection) based on particular property in ascending order. We can use OrderBy operator both in Query Syntax and Method Syntax. Below is the syntax of OrderBy operator. public static IOrderedEnumerable<TSource> OrderBy<TSource, TKey>(this IEnumerable<TSource> source, Func...

Continue Reading

LINQ OfType Filtering Operator

OfType comes in Filtering operator category. Here is list of all Query Operators. LINQ OfType operator filter the objects from a collection based on Types. In a collection, we have multiple elements of different Types and we have to select only those objects from the collection that are of specific Type. C# Example of OfType Operator in Query Syntax abstract class Course { pu...

Continue Reading

LINQ Where Filtering Operator

LINQ where operator comes in Filtering operators category. Here is a list of all LINQ Operators. Where operator filter the list based on some given criteria. Where operator is an extension method which accept a Func delegate as a parameter. Func accept only a single argument element. An element is passed to argument automatically by LINQ. In the predicate, we'll give a lambda expression whi...

Continue Reading

LINQ Filtering Operators with Examples in C#

Filtering operators are used to select only those elements from sequence that satisfy a condition. For example, suppose we have ten names in a collection sequence and we have to filter out those names that start with "K". Filtering Operators Description Where Filter elements based on the condition. OfType This operator takes a Type nam...

Continue Reading