LINQ API in C#

Sankhadip Samanta
3 min readJul 10, 2020
LINQ API

Language-Integrated Query (LINQ) is a powerful query language introduced with .Net 3.5 & Visual Studio 2008.

What is LINQ

LINQ API is a query syntax kit at the language level in C# and VB.NET to retrieve data from different sources(database). If we are using LINQ API, we don’t need to worry about data sources like ADO.NET, SQL, and many other databases. LINQ Query results in objects. Specifically, it lets us stay in an Object-Oriented Approach irrespective of Data Sources.

Standard Query Operators

Standard Query Operators are methods defined for IEnumerable and IQueryable types. There are more than 50 operators available in the LINQ API list which make code more concise and readable.

While using the LINQ API, we have two ways to implement them

  • Query
  • Method

Although syntax written in Query is converted in Method Syntax at compile time. Today we will look into some Query Operator to get familiar with LINQ API implementation.

For more detailed information about LINQ API visit

https://docs.microsoft.com/en-us/dotnet/standard/using-linq

Implementation

  1. Where
  • Query:
Where in Query Syntaxt
  • Method:
Where in Method Syntax

2. OfType

  • Query:
OfType in Query Syntax
  • Method:
OfType in Method Syntax

3. OrderBy

  • Query:
OrderBy in Query Syntax
  • Method:
OrderBy in Method Syntax

4. All

All Operator Implementation

5. Any

Any Operator Implementation

6. Count

Count Operator

7. Intersect

Intersect Operator

I have not imported System, System.Collections.Generic and System.Linq in the last couple of operators. But do write it, otherwise, it will throw compile-time error.

So, that’s some LINQ API implementation in C#. LINQ has been a great way to write code in a more concise, readable, and maintainability manner in C#.

If you are having any questions, leave a comment.

Also find me on Linkedin 😃 and Github 😅

Sankhadip Samanta

Full Stack Developer, Code Quotient | Tech Writer and Social Media Handler at BlogMarch

--

--