小编ABa*_*ney的帖子

Nullable Long switch语句在VS2015中没有产生预期输出

我在VS2015 Update 1中使用可以为空的长switch语句时看到了一些奇怪的行为,我在其他Visual Studio版本中没有看到它按预期运行.

class Program
{
    static void Main(string[] args)
    {
        NullableTest(-1);
        NullableTest(0);
        NullableTest(1);
        NullableTest(2);
        NullableTest(null);
    }

    public static void NullableTest(long? input)
    {
        string switch1;
        switch (input)
        {
            case 0:
                switch1 = "0";
                break;
            case 1:
                switch1 = "1";
                break;
            default:
                switch1 = "d";
                break;
        }

        string switch2;
        switch (input)
        {
            case -1:
                switch2 = "-1";
                break;
            case 0:
                switch2 = "0";
                break;
            case 1:
                switch2 = "1";
                break;
            default:
                switch2 = "d";
                break;
        }

        string ifElse;
        if (input …
Run Code Online (Sandbox Code Playgroud)

c# nullable switch-statement visual-studio-2015

9
推荐指数
1
解决办法
206
查看次数