Tag: LINQ

Example of Anonymous Type Indexes in For Loop in C#

The anonymous type (var) can be used to initialize the indexes in a for loop or the object within the for each loop. Below is a sample code snippet demonstrating the usage of the anonymous types in the For loop . Example of Anonymous Type Indexes in For Loop in C#

C# and LINQ – Filter elements from object collection with Logical Operators

Here’s a sample code snippet demonstrating how to filter elements from a list of objects using the where clause using LINQ in C#. This sample gets all the employees who salary is greater than 20000 GBP and age is greater than 22. How to Filter Employees List whose salary is greater than 20000 GBP and age is greater than 22 using LINQ in C# ?…

Deferred Execution Example in LINQ and C#

The Query Operators are executed only when enumerated except few scenarios. For example, when you use the for/Foreach statement and iterate the items from the query result. Below is a sample code demonstrating the Deferred Execution in C#. Deferred Execution Example in LINQ and C#

C# and LINQ – Finding all the elements of an integer array less than 35

Here’s a sample code snippet demonstrating how to find all the elements of an integer array that is less than 35 using LINQ in C#. The where keyword in C# is used to filter the elements from a collection based on the specified criteria. Ensure that you import the System.Linq namespace to your C# code. How to find all the elements of an integer array…

Concatenate or Join a string Array using LINQ in C#

Want to join the items inside the string array say with, delimiter using LINQ in C#? It’s pretty easy. Below is a sample code snippet demonstrating in easy steps on how to concatenate a string array using LINQ in C#? Concatenate or Join a string Array using LINQ in C#

How to Implement Multiple order by in LINQ using C#?

There are scenarios where one might want to implement multiple order by statements when using LINQ in C#. For example, you might want to sort the list of article by category and then by date. Below is a sample code snippet that demonstrates how to How to Implement Multiple order by in LINQ using C# ? How to Implement Multiple order by in LINQ using…

SelectMany Example in LINQ and C#

Below is a sample source code demonstrating the usage of the SelectMany method in LINQ and C#. One of the usage of the SelectMany is to return the flat list an avoid returning the lists of lists. SelectMany Example in LINQ and C#