What is LINQ?

Hakan Yalıtekin
2 min readMar 7, 2023

LINQ (Language Integrated Query) is a useful query language introduced with C# 3.0 by Microsoft, which allows us to query different data sources.

LINQ is an acronym for Language Integrated Query and provides a query syntax for querying different types of data sources including collections, ADO.NET DataSet, XML, SQL Server, Entity Framework and other databases. The following visual representation will help to understand it better.

There are two different syntaxes in LINQ:

  • Query Syntax (Query syntax) -> starts with “from”.
  • Method Syntax (Method syntax)

If we have previously written SQL commands, Query Syntax method will not be unfamiliar to us. Let’s examine both syntaxes with a small example.

// Data Source (This data can be provided from anywhere as mentioned above.)
int[] numbers = new int[] { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };

//QUERY SYNTAX
var smallNums = from num in numbers
where num < 5
select num;

//METHOD SYNTAX (My favorite🙂)
var smallNums2 = numbers.Where(x => x < 5);

// Using the written query
foreach (int numin smallNums)
{
Console.WriteLine(num);
}

Now that we have been introduced to LINQ, in order to fully understand its usage practices, we can download the lessons on GitHub and read them line by line. This link where you can download the lessons with a preview.

See you next article…

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response