What Is LINQ?
LINQ, short for Language Integrated Query, is a C# and .NET feature that lets you write queries directly inside your C# code using a consistent syntax, regardless of where the data actually lives. Whether you're querying an in-memory List<T>, a SQL Server table through Entity Framework Core, or an XML document, you use the same Where, Select, and OrderBy operators. This is possible because LINQ is built around two core interfaces, IEnumerable<T> and IQueryable<T>, and the extension methods defined in the System.Linq namespace.
Cricket analogy: Like the DRS system pulling ball-tracking, Snickometer and Hot Spot feeds into one unified review screen for the third umpire, LINQ pulls objects, SQL rows and XML nodes into one unified query syntax you write once.
Why LINQ Exists
Before LINQ shipped with C# 3.0 and .NET 3.5 in 2007, developers filtered and transformed data using hand-written foreach loops with mutable index variables, or by embedding raw SQL strings directly in code with no compile-time checking. Both approaches were verbose and error-prone: a typo in a SQL string only failed at runtime, and a subtle off-by-one bug in a loop could silently corrupt results. LINQ, together with lambda expressions, extension methods, and anonymous types introduced in the same release, replaced this with declarative queries that the compiler checks and IntelliSense understands.
Cricket analogy: Before neutral umpires were mandated by the ICC in the 1990s, home-team bias crept into decisions the way manual foreach loops let inconsistent, error-prone filtering logic creep into pre-LINQ C# code; LINQ, introduced in C# 3.0, standardized the process.
Core Building Blocks
Every LINQ query rests on the IEnumerable<T> interface (or IQueryable<T> for remote data sources) and a set of extension methods defined in System.Linq, such as Where, Select, OrderBy, and GroupBy. These methods accept lambda expressions — compact, inline functions like x => x.Age > 18 — as their filtering or projection logic. You can write the same query using either query syntax (from x in list where x.Age > 18 select x) or method syntax (list.Where(x => x.Age > 18)); both compile to the same underlying method calls.
Cricket analogy: Just as a bowler's toolkit includes the yorker, the googly, and the doosra — each a specific variation of the same core skill — LINQ's toolkit includes Where, Select, and OrderBy, each an extension method built on the same IEnumerable<T> interface.
using System;
using System.Collections.Generic;
using System.Linq;
var numbers = new List<int> { 4, 8, 15, 16, 23, 42 };
// Method syntax
var evensMethod = numbers.Where(n => n % 2 == 0).OrderByDescending(n => n);
// Query syntax (compiles to the same calls)
var evensQuery = from n in numbers
where n % 2 == 0
orderby n descending
select n;
foreach (var n in evensMethod)
Console.WriteLine(n); // 42, 16, 8, 4LINQ's extension methods live in the System.Linq namespace. If IntelliSense doesn't show Where, Select, or OrderBy on a List<T> or array, check that you have using System.Linq; at the top of the file — without it, none of the LINQ operators are visible.
- LINQ (Language Integrated Query) lets you write strongly-typed queries directly in C#, unified across in-memory collections, databases, and XML.
- It shipped with C# 3.0 and .NET 3.5 in 2007, alongside lambda expressions, extension methods, and anonymous types.
- LINQ replaced hand-written foreach loops and string-concatenated SQL with declarative, compiler-checked queries.
- Every LINQ query is built on IEnumerable<T> (local data) or IQueryable<T> (remote data) plus extension methods in System.Linq.
- Lambda expressions like x => x.Age > 18 supply the filtering or projection logic to operators like Where and Select.
- LINQ queries can be written in query syntax or method syntax; both compile to the same underlying method calls.
Practice what you learned
1. In which release did LINQ first ship?
2. Which namespace must be imported to access LINQ's standard query operators like Where and Select?
3. What is the primary interface that LINQ to Objects queries operate against?
4. What relationship exists between LINQ query syntax and method syntax?
5. What did LINQ primarily replace in pre-2007 C# code?
Was this page helpful?
You May Also Like
Query Syntax vs Method Syntax
LINQ offers two equivalent ways to write the same query — SQL-like query syntax and fluent, chainable method syntax — and knowing when to reach for each makes your code more readable and capable.
LINQ to Objects
LINQ to Objects is the flavor of LINQ that runs entirely in memory against IEnumerable<T> collections like arrays, List<T>, and Dictionary<T>, using compiled delegates rather than translated queries.
Deferred vs Immediate Execution
LINQ queries either execute immediately when defined or defer execution until enumerated — understanding which operators do which prevents subtle bugs and needless repeated work.
Related Reading
Related Study Notes in Microsoft Technologies
Browse all study notesWindows 10 / UWP Development Study Notes
.NET · 30 topics
Microsoft TechnologiesWindows Batch Scripting Study Notes
Batch · 30 topics
Microsoft TechnologiesMFC (Microsoft Foundation Classes) Study Notes
C++ · 30 topics
Microsoft TechnologiesSilverlight Study Notes
.NET · 30 topics
Microsoft TechnologiesXAML Study Notes
.NET · 30 topics
Microsoft TechnologiesWPF (Windows Presentation Foundation) Study Notes
.NET · 30 topics