Multiple statements in a switch expression: C# 8
问题 Switch expressions were introduced in C# 8. There's plenty of places in codebases, which may be rewritten in this new style. For example, I have some code, which is used for parsing packets from a stream of bytes: switch (command) { case Command.C1: return new P1(); case Command.C2: return new P2(); default: stream.Position++; return null; } The problem is - it can't be converted to a switch expression like return command switch { Command.C1 => new P1(), Command.C3 => new P2(), _ => { stream