Yes, a lambda expression is used to create an
anonymous function
.
As you have already discovered, you specify input parameters (if any) on the left side of the lambda operator and an expression or a statement block on the other side, to create a lambda expression.
It can be of two forms:
1. Expression lambda that has an expression as its body:
(input-parameters) => expression
2. Statement lambda that has a statement block as its body:
(input-parameters) => { <sequence-of-statements> }
The body of an expression lambda can consist of a method call.
It's much easier:
- to create lambda expressions and statements that incorporate asynchronous processing by using the async and await keywords.
- to convert any lambda expression to a delegate type.
More details can be found here:
Lambda expressions - C# reference | Microsoft Learn[
^]