C# Tutorial: LINQ Basics
Query collections with LINQ: Where, Select, OrderBy, GroupBy, First, Aggregate.
Language Integrated Query
LINQ adds SQL-like query capabilities directly to C# collections. It works on any `IEnumerable<T>` — arrays, lists, databases, XML.
LINQ operations are lazy — they run when you iterate or call ToList/ToArray.
What you'll learn in this C# linq basics tutorial
This interactive C# tutorial has 8 hands-on exercises. Estimated time: 20 minutes.
- Where (filter) — `Where` filters elements matching a predicate.
- Select (transform) — `Select` transforms each element.
- Chaining LINQ operations — Chain multiple LINQ methods to build a pipeline.
- OrderBy and ThenBy — Sort with `OrderBy` and add secondary sort with `ThenBy`.
- GroupBy — `GroupBy` groups elements by a key.
- Aggregates — `Count`, `Sum`, `Min`, `Max`, `Average` aggregate a collection into a single value.
- First, Single, Any, All — Predicates that return a single value or bool.
- Aggregate for custom reduction — `Aggregate` is the general fold operation.
C# LINQ Basics concepts covered
- Language Integrated Query