0

我需要比较 switch 语句中的 int ,但我不确定我是如何输入错误的。这是我的代码:

switch (y) {
    case int y isgreater(1, 411):
       // case code here...

为了简化我想要的,在 VB 中,代码将是:

Case >= 411:
  'Code here for case
4

1 回答 1

2

Objective-C 等基于 C 的语言不支持这种语法。只需使用一个if语句:

if (y >= 411) {
    // do stuff
}

switch语句中,每个case值都必须是离散常数。

switch (expression) {
    case 5:
        // stuff
        break;
    case 12:
        // stuff
        break:
    default:
        // stuff
        break;
}
于 2012-11-08T03:40:52.403 回答