Skip to content
Discussion options

You must be logged in to vote

It's not a bug, the switch expression takes precedence over the +.

If you put the expression in parenthesis, it works as you intended :

public int ArraySizeDelta1
{
    get
    {
        int delta = LeftPoint.ArraySizeDelta + RightPoint.ArraySizeDelta; // 1 + 1 = 2
        return delta switch
        {
            0 => 0,
            > 0 => 1, // correct, returns 1
            < 0 => -1,
        };
    }
}

public int ArraySizeDelta2
{
    get
    {
        return (LeftPoint.ArraySizeDelta + RightPoint.ArraySizeDelta) switch // 1 + 1 = 2
        {
            0 => 0,
            > 0 => 1, // correct choice, but returns 2
            < 0 => -1,
        };
    }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@RioMcBoo
Comment options

Answer selected by jnm2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants