Lambdas are simply a syntax for expressing anonymous methods, which have existed in the language since .NET 2.0.
There isn't much difference between e => e.objectParameter > 5
, a lambda which takes an object e
and returns a boolean, and the older syntax, delegate(MyObj e) { return e.objectParameter > 5;}
. If you're using Resharper, you can use it to translate any lambda to an anonymous method and vice versa.
As such, lambdas aren't equivalent to LINQ, they're a shorthand syntax for anonymous functions. However, they're a stepping stone towards LINQ.
LINQ is, in its essence, a way to filter, transform and manipulate collections using techniques borrowed from functional programming. These techniques rely on the concept of Functions as First Class Objects, meaning you call a method (say, your Where
above) and pass it a function which determines how the Where
filters. Using C# before lambdas, this would have been very cumbersome, with the coder forced to use the verbose anonymous delegate syntax, or create a named method for each Where
call. (To see how clunky this can look, check out Java 7's anonymous types). So lambdas were added to the language to allow LINQ queries to be succinct, readable and (frankly) usable.