Unified switch-when, if, catch-when #8396
Replies: 2 comments
-
I know that grammar that only changes the style without actually solving the problem will not be supported. try
{
}
catch switch
{
case IOException e if (e.Message.Length < i):
break;
case if (i < 3):
default:
break;
} |
Beta Was this translation helpful? Give feedback.
-
This is intentional as they are guard clauses, not conditional statements. So the language uses
You can use discard + when in switch statements: switch (...) {
case var _ when condition:
break;
} As for mixing catch with switch, check out: |
Beta Was this translation helpful? Give feedback.
-
The usage of 'when' and 'if' on switch is similar. But their keywords are different and there are no parentheses.
Their functions are the same, but they use completely different syntax.
Moreover, due to the support of pattern matching, multiple catches can be completely replaced by switches.
So now, some of these three functions are unnecessary.
And the swtich expression can discard+when, but the switch option cannot use default+when
Beta Was this translation helpful? Give feedback.
All reactions