0

In the old switch expression you could have a case do multiple things for example

switch (example)
{
    case 1:
        doThing1();
        doThing2();
        break;
    case 2:
        doThing3();
        break;
    default: throw new Exception();
}

Is it possible to do something similar in the new switch expression like this

example switch{
    1 => doThing1(), doThing2(),
    2 => doThing3(),
    _ => throw new Exception()
}

or do I have to use the old switch expression?

tholomew
  • 11
  • 1
  • 4
    The new switch expression is for when you are returning values only. There's no need for you to switch to using it just because it's new. – DavidG Dec 02 '21 at 13:12
  • Very fair, I mainly wanted to use it because I think it looks a lot cleaner. Thanks for the help! – tholomew Dec 02 '21 at 13:16

0 Answers0