Search⌘ K
AI Features

LINQ - Query Syntax

Explore LINQ query syntax in C# to extract and manipulate data from collections. Understand key clauses such as from, select, where, let, join, orderby, and group, and see how to apply them with practical examples in this lesson.

What is LINQ?

A query expression statement extracts specific information from a collection of data. The query syntax in C# is called Language Integrated Query, (LINQ). LINQs are used on collections of data, such as lists or arrays, which are container types for the IEnumerable<T> interface. Any container type of IEnumerable can use a LINQ.

To use a LINQ, include the following at the top of the code:

using system.Linq;// C# 10 comes with ImplicitUsings, meaning the most popular using namespaces such as this one are already built-in so there is no need to declare it

In the examples below, the various clauses that make up a query are covered. Clauses are a smaller syntax than a full expression; LINQs require multiple clauses to be a complete expression.

What is the from clause?

Queries always start with a from clause. The from ...