Back to course

Lambda Expressions

C# Zero to Hero: Comprehensive Programming Masterclass

Lambda Expressions

A lambda expression is an anonymous function that you can use to create delegates or expression tree types.

Syntax

(input-parameters) => expression

Example

csharp List numbers = new List { 5, 12, 8, 1 }; int count = numbers.Count(x => x > 10);

Here x => x > 10 is a lambda that checks if a number is greater than 10.