C# Feature β Lambda expressions
Overview
Section titled βOverviewβLambdas are anonymous functions with expression or block bodies, foundational to LINQ and functional patterns.
Introduced In
Section titled βIntroduced InβC# 3 (2007)
List<int> Filter(List<int> xs, Predicate<int> pred) { /* ... */ }var evens = numbers.Where(n => n % 2 == 0).ToList();Annotated Example
Section titled βAnnotated ExampleβFunc<int,int> square = x => x * x; // expression-bodiedConsole.WriteLine(square(5));Gotchas & Best Practices
Section titled βGotchas & Best Practicesβ- Capture semantics: avoid capturing loop variables incorrectly.
Related Features
Section titled βRelated FeaturesβVersion Notes
Section titled βVersion Notesβ- Default lambda parameters in C# 12.