Fundamentally, is there any difference between a single-line expression lambda and a statement lambda? Take the following code, for example:
private delegate void MyDelegate();
protected static void Main()
{
MyDelegate myDelegate1 = () => Console.WriteLine("Test 1");
MyDelegate myDelegate2 = () => { Console.WriteLine("Test 2"); };
myDelegate1();
myDelegate2();
Console.ReadKey();
}
While I prefer the first because I find the brackets to be ugly, is there anything different between the two (besides the obvious part about requiring brackets for multi-line statements)?
Same for the OP example, but after C# 6.0, allowing you to use same expression syntax to define normal non-lambda methods within a class. For example:
The above code snippet can be written only if the method can be turned into a single expression. In short, it can be used the expression lambda syntax, but not the statement lambda syntax.