Method Syntax vs Query Syntax

Alex Tolson
2 min readDec 6, 2023

--

By now, we know that LINQ stands for Language Integrated Query.

But what’s the language integrated part? It’s the syntax in which the query expression is written.

Query Syntax will ask 3 tasks:

Specify the data source. This is the list, array, or collection of data that will provide information.

Define the Query Expression. There’s 4 parts:

  1. The variable that holds the results.
  2. From — defines the data collection to which the filter will be applied.
  3. Where — defines the filter being applied to the data collection.
  4. Select — This keyword is needed to select the elements from the defined data collection, array, or list.

And once the first two are established,

Execute the task.

Let’s look at an example of what this looks like in Query syntax:

Query Syntax for LINQs

Now, let’s take a look at how to write the same code in Method syntax using the Where keyword:

This has been an overview of Method Syntax vs Query Syntax.

Thanks for Stopping By.

--

--