Tag: LINQ

How to Get the Top 5 elements from a List in C# ?

If you want to get the top 5 elements from a list in C# or skip the first item and get the next five elements from a List , you can use the Take and the Skip methods. How to Get the Top 5 elements from a List in C# ? Below is a sample code snippet demonstrating the usage of the Skip and Take…

How to Concatenate Strings in C# using LINQ?

Assume that you have an array/List of string which needs to be concatenated. One can concatenate strings using + operator, StringBuilder etc. . . . How about concatenating strings using LINQ? Below is a sample source code that demonstrates how to concatenate strings in C# using LINQ? How to Concatenate Strings in C# using LINQ?

Anonymous Types are read-only in C#

If you try to set a value to the anonymous type in C# , you will receive an compiler error . The properties within the anonymous types are read-only properties. Anonymous Types are read-only in C# In the above code snippet , you will receive an compiler error “Error    CS0200    Property or indexer ‘<anonymous type: string FirstName, string Last>.FirstName’ cannot be assigned to — it…

How to Perform Inner Join using LINQ in C# ?

Are you looking for the syntax on how to perform inner join using LINQ in C# ? . Below is a sample code snippet that demonstrates how to do it. How to Perform Inner Join using LINQ in C# ? Assume that the 2 objects that needs to be joined are Employee and EmployeeLeave as shown below. The employees and the leaves list contains the…

How to Create Pivot Data using LINQ in C#?

Are you looking forward to create a pivot data using LINQ in C#, here we go. How to Create Pivot Data using LINQ in C#? Below is a sample code snippet that demonstrates the creation of the Pivot Data using LINQ and C#?

Rules for using Anonymous Types in C#

The anonymous types (var) in C# is an interesting feature that the C# developers could use within their .NET application . When using the anonymous type , there are certain criteria or rules that needs to be followed . Rules for using Anonymous Types in C# Below are some of the rules that the developers should be following when using the anonymous type. 1. NULL…

Best Java Equivalent for LINQ (C#)

LINQ Query and Lambda expressions are one of the popular features of C# which helped the .NET developers in many ways. If you are a Java developer and wondering is there anything similar to this in Java ? ,this post will provide some insights on the additional APIs which could bring in the similar functionality Best Java Equivalent for LINQ (C#) jaque Another Java integrated…

C# and LINQ – Filter elements from object collection using where clause

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. How to Filter Employees List whose salary is greater than 20000 GBP using LINQ in C# ? Output Employees whose salary is greater than 20000 pounds Michael John

How to Get the Maximum value from a List of String using LINQ in C# ?

In one of the previous article , we explained how to get the maximum value from a list of integer using LINQ query in C# . What happens when the column is a string instead of integer ?. Below are 2 possibilities on how to get the maximum value from a list of string. How to Get the Maximum value from a List of String…