Lambda Expression

While Anonymous Methods were a new feature in 2.0, Lambda Expressions are simply an improvement to syntax when using Anonymous Methods, introduced in C# 3.0. Lambda Operator => was introduced so that there is no longer a need to use the delegate keyword, or provide the type of the parameter. The type can usually be inferred by compiler from usage. To test this, add a new class LambdaExpression.cs and write the following code

class LambdaExpression {
	static void Main() {
		SayDel sd = name => {
			return "Hello Mr. " + name + " have a nice day.";
		}
		;
		Console.WriteLine(sd("Raju"));
		Console.WriteLine(sd("Naresh"));
		Console.WriteLine(sd("Praveen"));
		Console.ReadLine();
	}
}
Syntax of defining Lambda Expression: [(] Parameters [)] => { Executed code };

Why would we need to write a method without a name is convenience i.e. 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 are short. It saves you the effort of declaring and writing a separate method to the containing class. Benefits are like Reduced typing, i.e. no need to specify the name of the function, its return type, and its access modifier as well as 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 calling code difficult to read.