LINQ
LINQ brings filtering, projection, ordering, grouping, and aggregation to strongly typed data.
How it works
Query collections with expressive, composable operators.
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.