Is there a way to make my switch/case fall through to the next case in C#?

后端 未结 4 1783
后悔当初
后悔当初 2021-02-19 03:28

I\'m using a switch/case statement to handle some updates for a deployed application. Basically, I want to waterfall through the cases to perform the update from the current run

4条回答
  •  遇见更好的自我
    2021-02-19 04:07

    This is a great example of how a poorly worded error message creates confusion. The rule of C# that is actually violated here is not that control has fallen through from one switch section to another; it is that the end point of every switch section must not be reachable. The error, by rights, should have been something like

    Endpoint of switch section for case "1" must not be reachable; consider adding 'break;'

    When we revisit the semantic analysis of switch statements for the Roslyn project I'll see if we can change the wording on this a bit to be more clear.

    For more analysis of this and related issues, see my article on the subject.

提交回复
热议问题