Lambda expressions in C# are a powerful feature that allow you to write concise & readable code. They provide a way to define anonymous functions inline, without the need for a separate method declaration. Lambda expressions are commonly used with LINQ queries, event handlers & delegate invocations.

Types of Lambda Expressions
Lambda expressions in C# can be classified into two main types:
- expression lambdas
- statement lambdas
Let's discuss both of these types in detail:
1. Expression Lambda
An expression lambda is a concise way to define a lambda expression that consists of a single expression. It is characterized by the absence of curly braces & an explicit return statement. The syntax for an expression lambda is as follows:
Syntax of Expression Lambda
(parameters) => expression
In this syntax, the parameters represent the input parameters of the lambda expression, & the expression is the single expression that is evaluated & returned as the result of the lambda expression. The arrow => separates the parameters from the expression.
2. Statement Lambda
Unlike expression lambdas, statement lambdas allow you to write multiple statements within the lambda expression. They are enclosed in curly braces & can contain multiple lines of code. Statement lambdas are useful when you need to perform more complex operations or have multiple statements to execute.
Syntax of Statement Lambda
(parameters) => { statements }
In this syntax, the parameters represent the input parameters of the lambda expression, & the statements are one or more C# statements that are executed when the lambda expression is invoked. The curly braces {} are used to enclose the statements.
Let's look at some examples to understand how to use lambda expressions in C#.
Example 1: Expression Lambda
Output:
25
In this example, we define an expression lambda square that takes an integer parameter x & returns the square of x. We assign the lambda expression to a Func<int, int> delegate, which represents a function that takes an integer parameter & returns an integer. We then invoke the lambda expression by calling square(5), which returns the result 25.