LINQ | Query Syntax Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report LINQ query syntax is consist of a set of query keywords defined into the .NET Framework version 3.5 or Higher. This allows the programmer or developers to write the commands similar to SQL style in the code(C# or VB.NET) without using quotes. It is also known as the Query Expression Syntax. In LINQ, you can write the query to IEnumerable collection or IQueryable data sources using the following ways: Query SyntaxMethod Syntax Here, we will discuss the Query Syntax only. Query Syntax The LINQ query syntax begins with from keyword and ends with the Select or GroupBy keyword. After from keyword you can use different types of Standard Query Operations like filtering, grouping, etc. according to your need. In LINQ, 50 different types of Standard Query Operators are available. Creating first LINQ Query using Query Syntax in C# Step 1: First add System.Linq namespace in your code.using System.Linq;Step 2: Next, create data source on which you want to perform operations. For example:List my_list = new List(){ "This is my Dog", "Name of my Dog is Robin", "This is my Cat", "Name of the cat is Mewmew" };Step 3: Now create the query using the query keywords like select, from, etc. For example: var res = from l in my_list where l.Contains("my") select l;Here res is the query variable which stores the result of the query expression. The from clause is used to specify the data source, i.e, my_list, where clause applies the filter, i.e, l.Contains("my") and select clause provides the type of the returned items. And l is the range variable.Step 4: Last step is to execute the query by using a foreach loop. For example:foreach(var q in res) { Console.WriteLine(q); } Example: CSharp // Create first Query in C# using System; using System.Linq; using System.Collections.Generic; class GFG { // Main Method static public void Main() { // Data source List<string> my_list = new List<string>() { "This is my Dog", "Name of my Dog is Robin", "This is my Cat", "Name of the cat is Mewmew" }; // Creating LINQ Query var res = from l in my_list where l.Contains("my") select l; // Executing LINQ Query foreach(var q in res) { Console.WriteLine(q); } } } Output: This is my Dog Name of my Dog is Robin This is my Cat Comment More infoAdvertise with us Next Article LINQ | Partition Operator | Take A ankita_saini Follow Improve Article Tags : C# CSharp LINQ Similar Reads LINQ | Method Syntax In LINQ, Method Syntax is used to call the extension methods of the Enumerable or Queryable static classes. It is also known as Method Extension Syntax or Fluent. However, the compiler always converts the query syntax in method syntax at compile time. It can invoke the standard query operator like S 2 min read What is Query in LINQ? A query is an expression which is used to recover data from the data source. Generally, queries are expressed in some specialized language. Different types of languages are developed to access the different type of data sources like SQL for a relational database, XQuery for XML, etc. So, every time 3 min read How to Convert SQL to LINQ Query? A group of technologies known as Language-Integrated Query (LINQ) is built on the direct integration of query functionality into the C# language. The query expression is the component of LINQ that stands out the most to developers who write LINQ queries. The declarative query syntax is used to write 3 min read LINQ | Set Operator | Union In LINQ, Set operators are those operators in query expression which return a result set which is based on the existence or non-existence of the equivalent elements within the same or different collections or sequences or sets. The standard query operator contains the following set operators: Union 3 min read LINQ | Partition Operator | Take In LINQ, partition operators are used for separating the given sequence into two portions without sorting the elements and return one of the portions. The Standard Query Operators supports 4 different types of partition operators: Skip SkipWhile Take TakeWhile Take Operator The Take operator is used 3 min read LINQ | Set Operator | Except In LINQ, Set operators are those operators in query expression which return a result set based on the existence or non-existence of the equivalent elements within the same or different collections or sequences or sets. The standard query operator contains the following set operators: Union Intersect 3 min read Like