What is a lambda expression in C#?

Answer

A lambda expression is an anonymous function — an inline function definition. Syntax: (parameters) => expression (expression lambda) or (parameters) => { statements } (statement lambda). Examples: Func<int, int> square = x => x * x;. Func<int, int, int> add = (a, b) => a + b;. Action<string> print = msg => Console.WriteLine(msg);. Lambdas can capture variables from the surrounding scope (closure): int multiplier = 3; Func<int, int> triple = x => x * multiplier;. Lambda expressions are extensively used in LINQ: list.Where(x => x > 5).Select(x => x * 2). They compile to either a delegate or an Expression<T> (used by Entity Framework to translate to SQL). Lambdas with captured variables create closure objects on the heap — be mindful in hot paths.