LINQ is a query syntax built into C#. It lets you ask a question of a collection, a database or an XML document using the same set of methods, and it reads close enough to English that a query usually explains itself.

Most LINQ methods are lazy. Nothing happens until you enumerate the result, so a query you build in one place can run somewhere else entirely. ToList and ToArray force it to run now.

LINQ to Objects and LINQ to Entities look identical on the page. Against a collection your code runs in memory. Against a database the same expression is translated into SQL, so some perfectly valid C# will simply fail to translate. The join and grouping articles below cover where the two diverge.

All ten LINQ articles are below.

Filtering and Projecting

Choosing which items you want, and reshaping them on the way out.

Joining and Grouping

Putting two sequences together, and splitting one into buckets.

Comparing and Converting Results

Finding differences between two sequences, turning a query into a dictionary, and processing results in batches.

Where to Go Next

What LINQ is usually querying:

When a query needs a comment to explain it, split it into two queries with names. It costs nothing at runtime and saves the next person who reads it.