A lambda expression is an anonymous function and it is mostly used to create delegates in LINQ. Simply put, it's a method without a declaration, i.e., access modifier, return value declaration, and name. Why do we need lambda expressions? (Why would we need to write a method without a name?)
Convenience. It's a shorthand that allows you to write a method in the same place you are going to use it. Especially useful in places where a method is being used only once, and the method definition is short. It saves you the effort of declaring and writing a separate method to the containing class.
Benefits: Reduced typing. No need to specify the name of the function, its return type, and its access modifier. When reading the code you don't need to look elsewhere for the method's definition.
Lambda expressions should be short. A complex definition makes the calling code difficult to read. How do we define a lambda expression?
A lambda expression is similar to a method except that it's written 'inline' and doesn't have a name. It is automatically converted to a delegate or expression tree of a compatible type.
When lambda expressions make use of 'outside' variables those variables are said to be 'captured' and their lifetime is extended to that of the lambda expression itself.
It is usually possible for the compiler to infer the types of the lambda expression's parameters from the context which means that they can be written quite concisely.
The convenience of being able to write and pass methods inline, in a concise fashion, makes lambda expressions particularly useful in LINQ where most extension methods take delegates as parameter.
Ramesh MaruthiPosted Oct 24, 2014, 4:51 PM
A lambda expression is an anonymous function and it is mostly used to create delegates in LINQ. Simply put, it's a method without a declaration, i.e., access modifier, return value declaration, and name.
Why do we need lambda expressions? (Why would we need to write a method without a name?)
Convenience. It's a shorthand that allows you to write a method in the same place you are going to use it. Especially useful in places where a method is being used only once, and the method definition is short. It saves you the effort of declaring and writing a separate method to the containing class.
Benefits:
Reduced typing. No need to specify the name of the function, its return type, and its access modifier.
When reading the code you don't need to look elsewhere for the method's definition.
Lambda expressions should be short. A complex definition makes the calling code difficult to read.
How do we define a lambda expression?
Lambda basic definition: Parameters => Executed code.
see this links :
http://www.dotnetperls.com/lambda
http://www.codeproject.com/Tips/298963/Understand-Lambda-Expressions-in-minutes
VulpesPosted Oct 24, 2014, 4:48 PM
http://msdn.microsoft.com/en-GB/library/bb397687.aspx