Wednesday, January 9, 2008

An introduction about Lambda Expressions

Ok start with a short introduction. With lambda expressions, we can define function objects for use at any time. C# has always supported this capability via delegates, whereby you create a function object and wire it up to the backing code at the time of creation. Lambda expressions join these two actions—creation and connection—into one expressive statement in the code. A functional is a function that takes functions in its parameter list and operates on those functions, possibly even returning another function as the result. For example, a functional could accept two functions, where one performs one mathematical operation and the other performs a different mathematical operation, and return a third function that is a composite function built from the two. Lambda expressions provide a more natural way to create and invoke functionals. In simple syntactic terms, lambda expressions are a syntax whereby you can declare anonymous functions (delegates) in a more fluid and expressive way. Lambda expressions really take two forms. The form that most directly replaces anonymous methods in syntax includes a statement block within braces. I like to refer to these as lambda statements. These lambda statements are a direct replacement for anonymous methods. Lambda expressions, on the other hand, provide an even more abbreviated way to declare an anonymous method and do not require code within braces nor a return statement. Both types of lambda expressions can be converted to delegates.

Zaq

1 comment:

Mamun said...

Hi Zaq,
Thanks for your nice post, i am java developer this help me to know about Lambda programming. Can u give an example please and uses of the lambda programming in the real life. Thanks again.

Mamun