This might be better titled "C# 8: switch expressions" (edit: it was previously "statement", as the author's post is titled). Or actually, to bait a few more hn clicks (and provide a fuller description): "Pattern matching in C# 8 with switch expressions"
This might be better titled "changing things for the sake of changing things and appealing to the programming language geeks". The new syntax is not intuitive, not more readable, just a bit more terse.
Once you start making switch expressions, the break keyword makes no sense. And with pattern matching the case keyword technically wouldn't be nessesary for normal switch statements already, might as well drop it for the new syntax.
I find this completely reasonable, and I think it's very readable, especially compared to the closest equivalents: putting a single switch in a function and calling that, or using nested tertiary operators:
const sqlOp = op switch {
"&&" => "AND",
"||" => "OR",
_ => throw new NotSupportedException()
}
vs function getSqlOp(string op) {
switch op {
case "&&": return "AND";
case "||": return "OR";
default: throw new NotSupportedException();
}
}
// ... far away
const sqlOp = getSqlOp(op);
vs const sqlOp = op=="&&" ? "AND" : op=="||" ? "OR" : throw new NotSupportedException();