Wednesday, 12 September 2007

C# 3.0 Basic - Lambda expressions

"A lambda expression is written as a parameter list, followed by the => token, followed by an expression or a statement block."

This is not the first time I see Lambda expressions. I love Lambda expressions in the first sight because the look pretty much like logic to me. Alex talked about this in his LINQ example. I will talk about it in LINQ later, but here are some examples I copy from c#3.0 specification document:

x => x + 1 // Implicitly typed, expression body
x => { return x + 1; } // Implicitly typed, statement body
(int x) => x + 1 // Explicitly typed, expression body
(int x) => { return x + 1; } // Explicitly typed, statement body
(x, y) => x * y // Multiple parameters
() => Console.WriteLine() // No parameters

Honestly I am not confident in typing an example for this in notepad and assume it will work. So i will go home and install VS 2008 beta on my machine first, have a try and create an example. Then I can create example for LINQ as well.:)

No comments:

Post a Comment