Following code fails with the CS0029 error. Indeed this code is wrong - you should either start with tuple and have cases for tuples, or start with single variable and match on strings. The question is what compiler actually tries to do and why it accepts switch (s1,s2) as valid part of switch statement.
CS0029 Cannot implicitly convert type 'string' to '(string s1, string s2)'
string s1 = "a", s2 = "b";
switch (s1,s2)
{
case "a": //CS0029
Console.WriteLine("A");
break;
default: break;
}
Variants that I expect to work (meaning it compiles and code in case runs):
tuple (braces around the tuple for the switch's syntax):
switch ((s1,s2)) {
case ("a","b"):...
or single variable:
switch(s1) {
case "a":
And one that I don't really expect to work but it does (which is what error message suggests essentially) - this case compiles and at run-time case code is executed (same way as switch ((s1,s2))):
switch (s1,s2) {
case ("a","b"):...
Based on behavior and the error it looks like switch (s1,s2) is treated as switch ((s1,s2)) but it is unclear why based on docs for the switch statement'
switch_statement : 'switch' '(' expression ')' switch_block ;
Inspired by currently deleted https://stackoverflow.com/questions/71803871