csharpstandard icon indicating copy to clipboard operation
csharpstandard copied to clipboard

8.0 Tuple parentheses optional in switch expression and statement

Open BillWagner opened this issue 3 years ago • 3 comments

When a tuple is used as the expression for a switch statement (or expression), the tuple doesn't need parentheses. For example:

void M(bool a, bool b)
{
    switch (a,b) // This is the tuple (a,b), but the parentheses are for the switch expression, not the tuple.
    {
        case (true, true):
            break;
        case (true, false):
            break;
        case (false, true):
            break;
        case (false, false):
            break;
            
    }
}

BillWagner avatar May 11 '22 21:05 BillWagner

This is specified in https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/patterns.md

gafter avatar May 13 '22 23:05 gafter

This is specified in https://github.com/dotnet/csharplang/blob/main/proposals/csharp-8.0/patterns.md

But this is not specified in 13.8.3 The switch statement, so this conflicts with the syntax in the standard, should it be updated together?

geniuszxy avatar Jan 03 '24 05:01 geniuszxy

The switch statement is modified to handle this in PR https://github.com/dotnet/csharpstandard/pull/873.

RexJaeschke avatar Jan 03 '24 12:01 RexJaeschke