Why we use lamdaexpression in c#?
c#
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Oct 24, 2014, 12:48 PM EDT
http://msdn.microsoft.com/en-GB/library/bb397687.aspx
Ramesh MaruthiRank #937 · 2.2K reputationPosted Oct 24, 2014, 12:51 PM EDT
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