0

I have trouble with using new 8.0 switch statment. In my case i don't need to return anything from switch nevertheless all examples i found uses return. I would like to have something like this below (psudo code). Keep in mind for some cases i need to put multilines. Is something like this possible?

operationType switch
                {
                    OpType.Handle
                    { 
                        //do something
                        //do something
                    }
                    OpType.Move => //do Something
                    _ => throw new ArgumentOutOfRangeException(nameof(operationType), operationType, null)
                };
Arie
  • 3,041
  • 7
  • 32
  • 63
  • 2
    *"i don't need to return anything from switch"* - use a `switch` *block* for that. – madreflection May 13 '20 at 21:26
  • 1
    They're not called "new `8.0` `switch` statment", they're called "[switch expressions](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#switch-expressions)", and they're just that: expressions. It is syntactic sugar to make your code more readable, and just look at the code you posted. Is that more readable that a couple of `if()`s? – CodeCaster May 13 '20 at 21:27
  • @CodeCaster so when i dont want to return anything should i just use normal switch statment? I thought i could rid off break for isntance.. – Arie May 13 '20 at 21:29

0 Answers0