Linq
is
always associated with
Lambda Expressions
.
In .NET 2.0 we have the concept of Annonymous Methods that allows you to write function body inline without the need of writing a delegate function.
Lambda Expression
of .NET 3.5 is to consize the concept of Annonymous function writing.
This CP article explains you about:
Basics of LINQ & Lamda Expressions[
^]
In addition,
You can use
Lambda Expressions
when you want to create a
delegate or an expression tree, basically.
Here are some examples
outside LINQ
:
- The old-style List<T>.ConvertAll/FindAll etc methods
- Starting new threads / tasks
- Attaching event handlers
- Providing an action in unit tests (e.g. "this action should throw an exception")
- Providing a value on request for Lazy<T>
Things which are only be achieved by Lambda expression & not by LINQ queries.
There are some
LINQ extension
methods which do not have counterparts in
LINQ query expressions
, and will
require the use of
Lambda Expressions
.
A good example is
Enumerable.ToLookup[
^] - if you want to create an ILookup, you
need to use lambdas
to generate this.