What Are Lambda Expressions?
Learn how to use lambda expressions with LINQ.
To work with LINQ, we need to be comfortable with delegates and lambda expressions. Let’s learn about them, starting with delegates.
What are delegates?
A delegate is a variable that references a method instead of a value or an object. In LINQ, Func
and Action
are the two built-in delegate types. We will be using Func
a lot with LINQ.
The difference between Func
and Action
is the return type of the method they point to. The Action
type references a void method. In other words, it references a method without return type. Conversely, Func
references a method with a return type.
Let’s look at some Func
and Action
declarations.
Action<Movie>
holds a method that receivesMovie
as a parameter and