switch 语句中的 switch 语句? [英] Switch statement inside a switch statement?

查看:67
本文介绍了switch 语句中的 switch 语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须评估许多条件.就我而言,我必须这样做:

I have to evaluate many conditions. In my case, I have to do something like this:

switch(id)
{
    case 5:
         // switch some other cases here
    case 6:
         // set some value
    ...
 }

在第 5 种情况下再进行一次切换是一种好习惯吗?如果不是,什么更好?有 if 语句吗?

Is it good practice to have another switch in case 5? If not, what's better? Having if statements there?

推荐答案

我会调用一个特定于案例 5 的函数,然后在该函数中使用 switch case.例如:

I'd call a function that was specific to case 5, then have the switch case in that function. For example :

switch(id)
{
    case 5:
         FunctionFiveSpecific(id);
    case 6:
         // set some value
    ...
 }

案例 5 特有的函数:

The function specific for case 5 :

private void FunctionFiveSpecific(id)
{
   // other switch in here
}

这篇关于switch 语句中的 switch 语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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