【发布时间】:2020-02-20 08:51:25
【问题描述】:
我有一些需要转换的数据,因为我需要一个超过 50 个案例的切换条件,我需要 3 次相同的案例,但第三次我需要 50 个案例和更多案例,但我不需要想写两次相同的代码。也许有可能做这样的事情。
switch (example)
{
case "1":
//do something
case "2":
//do something
case "50":
//do something
//now maybe something like this
if (condition == true)
{
case "1":
//do something else than above at case "1", and so on
//now its i little bit illogical, but i neet to do the first 50 cases and then
//use the cases 1 to 50 again but with other actions
}
}
【问题讨论】:
-
你的问题不清楚,你在找什么?
-
那么,在
case "50"你也想检查case "51"等等? -
你可以试试goto语句,虽然不推荐
-
你对 1-50(条件 == false)和条件为 true 的 1-50 的操作是什么样的?
标签: c# if-statement switch-statement case