Multiple statements in a switch expression: C# 8
Your only supported choice is the func like you did. See this article for more information. His example:
var result = operation switch
{
"+" => ((Func<int>)(() => {
Log("addition");
return a + b;
}))(),
"-" => ((Func<int>)(() => {
Log("subtraction");
return a - b;
}))(),
"/" => ((Func<int>)(() => {
Log("division");
return a / b;
}))(),
_ => throw new NotSupportedException()
};
Just because switch expressions are new doesn't mean they are the best for all use cases. They are not designed to contain multiple commands.