LINQ was introduced in C# 3.0. It combines language features and framework extensions so you can express data queries directly in C#.
Why it matters
LINQ matters because it replaces hand-written iteration with intent-focused operators. You can read the shape of the data transformation from left to right instead of tracing index updates and accumulator variables.
It also works across different backends. In-memory collections, XML, and many data providers can all use the same query style.
Cautions
Not every loop should become LINQ. If the code relies on side effects, early exits, or complex branching, a simple foreach can be clearer.
Also remember that deferred execution can delay work until enumeration time, which is useful but easy to forget when debugging.
Filtering and projecting data
LINQ turns sequence processing into a readable pipeline instead of nested loops and temp variables.
Valid since C# 3.0
var people = new[]
{
new { Age = 30, LastName = "Smith", FullName = "Alice Smith" },
new { Age = 16, LastName = "Jones", FullName = "Bob Jones" },
new { Age = 25, LastName = "Brown", FullName = "Carol Brown" },
};
var adults = people
.Where(person => person.Age >= 18)
.OrderBy(person => person.LastName)
.Select(person => person.FullName);