使用goto跳转到switch的某个case

2019-09-26 13:08:47 浏览数 (1)

代码语言:javascript复制
    switch(n)
        {
        case 1:
            cost  = 25;
            break;
        case 2:
            cost  = 25;
            goto case 1;
        case 3:
            cost  = 50;
            goto case 1;
        default:
            Console.WriteLine("Invalid selection. Please select 1, 2, or 3.");
            break;
        }

如果是string的case,同样可以跳转:goto case "name";

0 人点赞