Modern .NET APIs · 9 min read · Beginner
LINQ & Collections
Query, filter, sort, and project in-memory collections declaratively using C#'s LINQ extension methods.
What you'll learn
- Filter collections with .Where() and project values with .Select()
- Sort and aggregate cleanly using .OrderByDescending(), .Sum(), and .Average()
- Understand deferred execution and when to materialize with .ToList()
LINQ (Language Integrated Query) is one of C#‘s signature features. It brings SQL-like querying (Where, Select, OrderBy, GroupBy, Sum) directly into C# with full compile-time type safety and autocomplete.
Deferred Execution
LINQ queries like items.Where(...) are lazy: they do not execute until you iterate over them (with foreach) or materialize them with .ToList(), .Count(), or .Sum().
Fill-in-the-Blank Exercise
Filter & Project with LINQ
Keep scores of 80+ and format each as a string label.
var labels = scores
.(s => s >= 80)
.(s => $"Pass ({s})")
.ToList();Interactive Code Lab
C#LinqDemo.cs
Expected OutputClick “Run Live” to compile with Mono C#
C#, Java, OOP Total hours: 21
Check Your Understanding
Score: 0 / 1
1. Which LINQ method transforms (maps) every element in a sequence into a new shape?
Study Workspace
Finished this lesson?
Your progress is saved locally in your browser, no account needed.