Search This Blog

SQL server 2008 : LAMBDA EXPRESSIONS

C# 2.0 provided a shorthand method of creating methods and instantiating delegates all in one construct, known as anonymous delegates. C# 3.0 expanded on this idea with a more compact syntactical construct for creating anonymous methods known as lambda expressions. On its most basic level, a lambda expression is simply an anonymous function or method. In Listing 13-8, I've used lambda expressions in two places as arguments to the Average method. The lambda expressions I used were as follows:
p => (float)p.Element("open")
p => (float)p.Element("close")

In both of the preceding lambda expressions, the anonymous function is both declared and instantiated in one expression. Query methods, like the Average method, can accept anonymous functions as parameters— a very powerful feature. Lambda expressions offer many advantages (apart from terseness of code) that .NET 2.0 anonymous delegates do not provide: