标签: switch-statement

在C#中无法在交换机中使用小数范围?

我刚刚开始学习C#而且我已经陷入了一些非常基础的问题.

对于我的第一个"应用程序",我以为我会选择简单的东西,所以我决定使用BMI计算器.

BMI被计算成一个十进制类型,我现在试图在switch语句中使用,但是几乎不能在开关中使用十进制?

这个C#解决方案是什么:

            decimal bmi = calculate_bmi(h, w);

            switch (bmi) {
                case < 18.5: 
                    bmi_description = "underweight.";
                    break;
                case > 25:
                    bmi_description = "overweight";
                case > 30:
                    bmi_description = "very overweight";
                case > 40:
                    bmi_description = "extreme overweight";
                    break;
            }
Run Code Online (Sandbox Code Playgroud)

c# decimal switch-statement

18
推荐指数
2
解决办法
1万
查看次数

如何禁用UISwitch?

这是否可以禁用UISwitch?我并不是说将其置于关闭状态,我的意思是禁用用户交互,并使其显示为灰色.

在我的应用程序中,我有两个条件

if (condition == true) {  
  // UISwitch should be enabled  
} else {  
  // UISwitch should be visible, but disabled  
  // e.g uiswitch.enable=NO;  
} 
Run Code Online (Sandbox Code Playgroud)

有什么建议?

iphone objective-c switch-statement uiswitch

18
推荐指数
3
解决办法
2万
查看次数

如何在SQL Server中使用Switch

我想CASE在我的存储过程中使用.我的代码中出现了一些语法错误:

select 
   case @Temp
   when 1 then (@selectoneCount=@selectoneCount+1)
   when 2 then (@selectoneCount=@selectoneCount+1)
   end
Run Code Online (Sandbox Code Playgroud)

跑步时,我得到:

'='附近的语法不正确.

在这一行:

@selectoneCount = @selectoneCount + 1
Run Code Online (Sandbox Code Playgroud)

接近平等.

实际上我从另一个sp获得返回值到@temp然后如果@temp = 1那么我想将@SelectoneCount的计数增加1,依此类推.请告诉我正确的语法是什么.

sql-server syntax-error switch-statement

18
推荐指数
2
解决办法
11万
查看次数

Java:我可以在switch语句中只涉及一个案例

在Java中,我是否只能通过switch声明中的一个案例?我明白,如果我break,我会落到switch声明的最后.

这就是我的意思.鉴于以下代码,在案例2中,我想执行案例2和案例1.在案例3中,我想执行案例3和案例1,但不是案例2.

switch(option) {
    case 3:  // code
             // skip the next case, not break
    case 2:  // code
    case 1:  // code
}
Run Code Online (Sandbox Code Playgroud)

java switch-statement

18
推荐指数
3
解决办法
1万
查看次数

switch语句中的最终变量大小写

        final int a = 1;
        final int b;
        b = 2;
        final int x = 0;

        switch (x) {
            case a:break;     // ok
            case b:break;     // compiler error: Constant expression required

        }
        /* COMPILER RESULT:
                constant expression required
                case b:break;
                     ^
                1 error
        */
Run Code Online (Sandbox Code Playgroud)

为什么我会遇到这种错误?如果我愿意final int b = 2,一切正常.

java final case switch-statement

18
推荐指数
2
解决办法
2万
查看次数

记录故意切换的最佳方法是什么?

我发现自己处于切换机箱跌落的最佳选择.我的意思是:

switch($bar)
{
    case 0:
        // do something
    case 1:
        // do more
        break;
    //more cases
}
Run Code Online (Sandbox Code Playgroud)

目前我的IDE(phpStorm)正在发出关于坠落的警告.

在phpDoc中是否有一种可接受的方式来记录这种预期的漏洞?

我知道你们中的一些人无疑会说不要这样做,但我赞同这个邪恶的定义,这肯定是"替代品中最不好的".

php phpdoc switch-statement phpstorm

18
推荐指数
1
解决办法
3407
查看次数

是否可以在switch语句中使用.contains()?

这只是我正在尝试做的一个简单示例:

switch (window.location.href.contains('')) {
    case "google":
        searchWithGoogle();
        break;
    case "yahoo":
        searchWithYahoo();
        break;
    default:
        console.log("no search engine found");
}
Run Code Online (Sandbox Code Playgroud)

如果不可能/可行什么是更好的选择?

解:

在阅读了一些回复之后,我发现以下内容是一个简单的解决方案.

function winLocation(term) {
    return window.location.href.contains(term);
}
switch (true) {
    case winLocation("google"):
        searchWithGoogle();
        break;
    case winLocation("yahoo"):
        searchWithYahoo();
        break;
    default:
        console.log("no search engine found");
}
Run Code Online (Sandbox Code Playgroud)

javascript contains switch-statement

18
推荐指数
2
解决办法
2万
查看次数

c ++警告:交换机中未处理枚举值[-Wswitch]

我试图在没有警告的情况下编译以下代码:

    while (window.pollEvent(event))
    {
        switch (event.type) {
            case sf::Event::Closed:
                window.close(); break;
            case sf::Event::KeyPressed:
                if(event.key.code == sf::Keyboard::Escape )
                    window.close();
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Space ) )
                    particleSystem.fuel( 200/* * window.getFrameTime() */);
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::A ) )
                    particleSystem.setPosition( --xpos, ypos );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::D ) )
                    particleSystem.setPosition( ++xpos, ypos );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::W ) )
                    particleSystem.setPosition( xpos, --ypos );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::S ) )
                    particleSystem.setPosition( xpos, ++ypos );
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Left ) )
                    particleSystem.setGravity( --xgrv * 0.1f, ygrv * 0.1f);
                if( sf::Keyboard::isKeyPressed( sf::Keyboard::Right ) …
Run Code Online (Sandbox Code Playgroud)

c++ warnings compiler-warnings switch-statement

18
推荐指数
1
解决办法
2万
查看次数

切换/切换div(jquery)

我希望完成一项相当简单的任务(我希望!)

我有两个div标签和1个锚标签,如下所示:

<a href="javascript:void(0);">forgot password?</a>
<div id="login-form"></div>
<div id="recover-password" style="display:none;"></div>
Run Code Online (Sandbox Code Playgroud)

我想要完成的是使用锚标签在两个div标签之间切换,隐藏一个标签并显示另一个标签,反之亦然.

如何才能以最佳方式完成?

最好的祝福.

html jquery toggle switch-statement

17
推荐指数
2
解决办法
11万
查看次数

C++/C++ 11 - 可变参数模板的switch语句?

假设我有一些像这样的结构:

struct MyStruct1 {

    inline void DoSomething() {
        cout << "I'm number one!" << endl;
    }

};

struct MyStruct2 {

    static int DoSomething() {

        cout << "I'm the runner up." << endl;
        return 1;

    }

};

struct MyStruct3 {

    void (*DoSomething)();

    MyStruct3() {
        DoSomething = &InternalFunction;
    }

    static void InternalFunction() {
        cout << "I'm the tricky loser." << endl;
    }

};
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,对于所有三个结构,我可以在该结构的对象上调用DoSomething()并使其工作(尽管每个结构的实现方式不同):

MyStruct1 a;
MyStruct2 b;
MyStruct3 c;

a.DoSomething(); // works, calls Struct1's instance function
b.DoSomething(); // works, calls Struct2's …
Run Code Online (Sandbox Code Playgroud)

templates metaprogramming variadic switch-statement c++11

17
推荐指数
1
解决办法
6596
查看次数