Expand Lambda Function
Expands the lambda function with an expression body onto the lambda function with a block body. You can use this code formatter when you need to extend the code logic in the lambda function and the expression body is not appropriate for this task.
Availability
Available when the caret is in a lambda operator (=>).
Usage
Place the caret in a lambda operator (=>).
using System; namespace ConsoleApp { public class ExpandLambda { Func<string, int> func = s => s == null ? 0 : s.Length; } }
Press the Ctrl+. or Ctrl+~ shortcut to invoke the Code Actions menu.
Select Expand Lambda Function from the menu and press Enter.
After execution, this code formatter expands a single-line lambda function onto a lambda function with a code block body.
using System;
namespace ConsoleApp {
public class ExpandLambda {
Func<string, int> func = s => {
return s == null ? 0 : s.Length;
};
}
}