Beginning C# 7 Hands-On:Advanced Language Features
上QQ阅读APP看书,第一时间看更新

Creating an expression-bodied lambda

Next, you'll define the body of the Lambda. Because this lambda will do several things, you can enclose the body of it within a set of curly braces as follows:

{
double x = xin, y = yin;
}

So, this line assigns the values from the parameters above.

Next enter the following directly below this line:

return x > y ? x : y;

So, if x is greater than y, then return x; otherwise, return y. This is an expression-bodied Lambda, and you close it at the end with a semicolon after the closed curly brace, like this };. As you can see, this Lambda expression spans multiple lines. So, you can again inline code just as with the preceding line, using the double FromStringToDouble(string s) => Convert.ToDouble(s); function.