LINQ API in C#
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
Implementation
- Where
- Query:
- Method:
2. OfType
- Query:
- Method:
3. OrderBy
- Query:
- Method:
4. All
5. Any
6. Count
7. Intersect
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#.