// Prints "Enjoy your string!" to the console.
VerySimpleDelegate d = new VerySimpleDelegate( () => {return "Enjoy your string!";} );
Console.WriteLine(d.Invoke());
So hopefully at this point you can see the overall role of lambda expressions and understand
how they provide a “functional manner” to work with anonymous methods and delegate types.
Although the new lambda operator (=>) might take a bit to get used to, always remember a lambda
expression can be broken down to the following simple equation:
ArgumentsToProcess => StatementsToProcessThem
C H A P T E R 1 1
■
D E L E G AT E S, E V E N T S, A N D L A M B D A S
380
8849CH11.qxd 10/1/07 10:43 AM Page 380
It is worth pointing out that the LINQ programming model also makes substantial use of
lambda expressions to help simplify your coding efforts. You will examine LINQ beginning in
Chapter 14.
Do'stlaringiz bilan baham: |