我有一个switch语句,如下所示:
switch (condition)
{
case 0:
case 1:
// Do Something
break;
case 2:
// Do Something
case 3:
// Do Something
break;
}
Run Code Online (Sandbox Code Playgroud)
我收到编译错误告诉我 Control cannot fall through from one case label ('case 2:') to another
嗯......是的,你可以.因为你是从做它case 0:通过对case 1:.
事实上,如果我删除了我case 2:和它的相关任务,代码就会编译并从中case 0:进入case1:.
那么这里发生了什么,我怎样才能让我的case语句通过并执行一些中间代码?