ReSharper说代码“历史上无法到达”,但不是吗?

我有一个简单的实用程序方法,该方法采用小数点英寸值并返回一个分数(即,将1.5变成1 1/2“)用于显示。这很好,但是Resharper告诉我开关中的每种情况都是“无法到达”并发出警告,我不知道为什么。这是方法:

static string FractionalInches(double decimalInches)
{
    //Set initial variables
    string fraction = "";

    //Round to an integer for full inches
    int test = (int)Math.Round(decimalInches, 0);

    if (Math.Abs(decimalInches-test) < SharedData.FloatPointTolerance) //Even inches, no fractions here
    { return test.ToString(); }

    //Has a fraction
    var fullInches = decimalInches - test < 0 ? test - 1 : test;

    //get the fraction - rounded to 16ths.
    double sixteenths = Math.Abs(decimalInches - test) * 16;
    int sixt = (int)Math.Round(sixteenths, 0);

    switch (sixt)
    {
        case 1:
            fraction = "1/16";
            break;
        case 2:
            fraction = "1/8";
            break;
        case 3:
            fraction = "3/16";
            break;
        case 4:
            fraction = "1/4";
            break;
        case 5:
            fraction = "5/16";
            break;
        case 6:
            fraction = "3/8";
            break;
        case 7:
            fraction = "7/16";
            break;
        case 8:
            fraction = "1/2";
            break;
        case 9:
            fraction = "9/16";
            break;
        case 10:
            fraction = "5/8";
            break;
        case 11:
            fraction = "11/16";
            break;
        case 12:
            fraction = "3/4";
            break;
        case 13:
            fraction = "13/16";
            break;
        case 14:
            fraction = "7/8";
            break;
        case 15:
            fraction = "15/16";
            break;
        case 16:
            fraction = "";
            fullInches += 1;
            break;
    }

    //construct and return the final string
    return fraction == "" ? fullInches.ToString() : fullInches + " " + fraction;
}

它为我在switch语句中的每种情况下都提供了无法到达的警告,但是我知道它会被击中,因为我可以发送十进制值,并且它们返回正确的分数...有人知道为什么R#会发出此警告吗?我可以很容易地忽略它,但是不明白为什么它首先存在。

评论