How do I write a method with "=>" that is multi lined?
public int SimpleAddition(int firstInt, int secondInt) => firstInt + secondInt;
If I am not mistaken, the above method is equivalent to:
public int SimpleAddition(int firstInt, int secondInt){
return firstInt + secondInt;
}
How would I write this method using "=>" if logic spans multiple lines?
public int SimpleAddition(int firstInt, int secondInt){
//do something else here//
return firstInt + secondInt;
}
You would not. The following:
is expression-bodied method and expression-bodied members as the documentation states can consist only from single expression:
Note that several chained method calls for example (like fluent APIs/LINQ) still form a single expression. For example:
So if you can rewrite your additional code in a way that it can be chained (or form a single expression) then you will be able to rewrite method to be expression-bodied (does not mean that you should though).