在C#开关空情况下一个非空的一个组合? [英] Is empty case of switch in C# combined with the next non-empty one?

查看:90
本文介绍了在C#开关空情况下一个非空的一个组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码:

case "GETSITES":
case "SITESETUP":
    MessageBox.Show("Help! I am suffering from the Air-Conditioned Nightmare!!!");
    // ...



请问 MessageBox.Show 执行或者开关值GETSITESSITESETUP

Will the MessageBox.Show be executed either the switch value is "GETSITES" or "SITESETUP"?

如果开关值SITESETUP

由于GETSITES没有休息,我想是的,但我不知道。

Since "GETSITES" has no break, I'm thinking yes, but am not sure.

更新

我想我应该措辞我的问题的方式:

I guess the way I should have worded my question as:

是这两个代码段语义上等价

Are these two code fragments semantically equivalent?


  • 片段1

  • fragment 1

case 0:
case 1:
    // bla bla bla;
    break;


  • 片段2(伪代码)

  • fragment 2(pseudo code)

    case 0, 1:
        // bla bla bla;
        break;
    


  • 推荐答案

    你所描述的有两个标签相同的情况。 C#确实允许这一点。你可以没有,但是,始终陷入下一个case语句以同样的方式,C允许,也就是你的标签不能有一些代码,然后到下一个case语句下降。这是被禁止的,并会导致编译错误。

    What you are describing is having two labels for the same case. C# does allow this. You cannot, however, fall through to the next case statement in the same way that C allows, that is, your label cannot have some code, then fall through to the next case statement. That is forbidden and will cause a compilation error.

    这篇关于在C#开关空情况下一个非空的一个组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆