LINQ
Query collections with expressive, composable operators.
Introduction
LINQ brings filtering, projection, ordering, grouping, and aggregation to strongly typed data.
Where filters values, OrderBy sorts them, and Select transforms each result. Execution occurs when the sequence is enumerated.
Runnable C# example
Program.cs
using System;
using System.Linq;
class Program
{
static void Main()
{
var results = new[] { 7, 2, 9, 4, 6 }
.Where(number => number % 2 == 0)
.OrderBy(number => number)
.Select(number => number * number);
Console.WriteLine(string.Join(", ", results));
}
}
4, 16, 36Practice with the debugger
Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.
Practice with a challenge
Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.
- Above-Average Values Keep the values that are greater than the average. Easy
- Tournament Standings Rank teams from match records. Medium