c# - 有没有办法让我的 switch/case 进入 C# 中的下一个 case?

标签 c# switch-statement

我正在使用 switch/case 语句来处理已部署应用程序的一些更新。基本上,我想通过案例瀑布来执行从当前运行版本到最新版本的更新。

从对我大喊大叫的 Visual Studio 中,我了解到 C# 不允许进入下一个案例(这正是我想要做的)。来自 this question ,我学会了如何做我想做的事。但是,这显然仍然是一个错误。

我得到的是

switch (myCurrentVersion)
{
    case null:
    case "":
    case "0":
        UpdateToV1();
        goto case "1";
    case "1":
        UpdateToV2();
}

我在 case "1": 行收到以下错误:

Error 1 Control cannot fall through from one case label ('case "1":') to another

我做错了什么吗?我怎样才能迫使它落空?

最佳答案

即使是最后一种情况,你也需要添加一个break语句:

switch (myCurrentVersion)
{
    case null:
    case "":
    case "0":
        UpdateToV1();
        goto case "1";
    case "1":
        UpdateToV2();
        break;
}

关于c# - 有没有办法让我的 switch/case 进入 C# 中的下一个 case?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8071655/

相关文章:

C# 泛型和 void 的特例

未完全应用任何大小矩阵(1x1、3x3、5x5,...)的 C# 卷积过滤器

c - Domino 程序问题

algorithm - 如何优化多(矩阵)开关/案例算法?

c# - 如何安排在我的 MVC 网络应用程序中自动运行 Controller ?

C# 对象组合

java - Android Java - 开关问题

安卓 "Toggle off all buttons"

jquery - 如何为 jQuery 制作 switch case?

c# - 使用 NLog 配置 API 写入 ApplicationData 文件夹