True or False: If a match expression doesn't match any case pattern and there's no default case, control falls through a switch statement.
What does "control falls through a switch statement" mean in this context? Control just moves on to the next statement?
I thought if there is no match and a default case doesn't exist it will raise an exception. Is it not true?
https://learn.microsoft.com/en-US/dotnet/csharp/language-reference/statements/selection-statements#the-switch-statementOpen linkView original on programming.dev
Means it will be skipped entirely
I see, thank you! I got confused with "control falls through a switch statement" and "C++ style fall through in switch statements".
C# will let you forget simple things and crash or compile error further down the line.
Unlike c++? Hehe
A switch statement will let control fall through. A switch expression will no, and will throw an exception (and there will also be a compiler warning that it's not exhaustive before you even run the code)
I think even
switchstatement doesn't allow it because every case needs to be terminated with eitherbreak,returnorraise. One needs to usecase gotoif one wants fall thought like behavior:A
switchstatement allows fall through when the case itself doesn't have an implementation.For example this is also considered a fall through:
TIL!!!
Thank you!