Is empty case of switch in C# combined with the next non-empty one?(C# 中 switch 的空情况是否与下一个非空情况相结合?)
问题描述
使用以下代码:
case "GETSITES":
case "SITESETUP":
MessageBox.Show("Help! I am suffering from the Air-Conditioned Nightmare!!!");
// ...
MessageBox.Show 是否会被执行,开关值是 "GETSITES" 还是 "SITESETUP"?
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# 确实允许这样做.但是,您不能以 C 允许的相同方式进入下一个 case 语句,也就是说,您的标签不能有一些代码,然后进入下一个 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# 中 switch 的空情况是否与下一个非空情况相结合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C# 中 switch 的空情况是否与下一个非空情况相结合?
基础教程推荐
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
