Skip to content

Lambda expressions

Context: Lambda expressions are anonymous functions written inline. They are concise and widely used in LINQ, events, and functional programming.

Func<int, int> square = x => x * x;
Console.WriteLine(square(5)); // 25

LINQ queries: Lambdas are the core of LINQ: Where(x => x > 5), Select(x => x.Name), OrderBy(x => x.Date).

Example: Enumerable.Where expects a Func<TSource, bool> lambda.