如何使用C#使用当前case语句的值在切换案例条件下跳转到另一个case语句 [英] How to jump to another case statement in a switch-case condition with the value of current case statement using C#

查看:60
本文介绍了如何使用C#使用当前case语句的值在切换案例条件下跳转到另一个case语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在切换案例条件下使用当前案例语句的值跳转到另一个案例语句?

How do I jump to another case statement in a switch-case condition with the value of current case statement?

是否可以使用切换用例来实现这种事情?或者还有另一种实现方法吗?

Is it possible to implement this kind of things using switch case or is there another way to implement it?

有可能实现吗?如果没有,那么还有其他方法可以实现吗?

Is it possible to achieve? If not, then is there another way to achieve it?

推荐答案

此代码有效:

    switch (this.Name)
    {
    case "":
        if (this.Owner == null)
        {
            goto DoBill;
        }
        break;
    case "Bill":
    DoBill:
        break;
    }

但是,任何确实这样做的人都应该被枪杀.或至少进行了认真的交谈.为什么不做明智的事情呢?

However, anyone who actually does it should be shot. Or talked to very severely, at the least. Why not just do the sensible thing?

switch (param.Component.Type)
    {
        case "Combo":
            returnComboItemSelect = generateCB(param);
             if(returnComboItemSelect=="Slider")
             {
               returnSomething  = generateSl(param,returnComboItemSelect); //I mean no need to jump
             }
            break;                            
        case "List":
            returnSomething = generateL(param);
            break;
        case "Slider":
            returnSomething 
.....

严重的是,如果您开始在case语句之间跳来跳去,那么您就不应该使用它们.我也不喜欢上面的代码(重复,但有时...)

Seriously, if you start jumping about between case statements then you shouldn't be using them. I'm not too keen on the code above either (duplication, but sometimes...)

这篇关于如何使用C#使用当前case语句的值在切换案例条件下跳转到另一个case语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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