Just had a look at the "new" C# 8.0 Features
So I tried to rewrite the following code
private static void RunExample(ExampleCode exampleCode)
{
switch(exampleCode)
{
case ExampleCode.DefaultInterfaceMethod:
RunDefaultInterfaceMethodExample();
break;
case ExampleCode.PatternMatchingEnhancements:
RunPatternMatchingEnhancementsExample();
break;
}
}
to this:
private static void RunExample(ExampleCode exampleCode)
{
exampleCode switch
{
ExampleCode.DefaultInterfaceMethod => RunDefaultInterfaceMethodExample(),
ExampleCode.PatternMatchingEnhancements => RunPatternMatchingEnhancementsExample()
};
}
However, I am getting the following compile error:
Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement.
How can I rewrite this in the new syntax?