I have no idea why I’m getting this following error:
Control cannot fall through from one case label (‘case “h”:’) to another (CS0163)
Only for H and S – quite strange.
switch(myChoice)
{
case "K":
case "k":
Console.WriteLine("You have chosen the Kanto region");
break;
case "O":
case "o":
Console.WriteLine("You have chosen the Orange Islands");
break;
case "J":
case "j":
Console.WriteLine("You have chosen the Johto region");
break;
case "H":
case "h":
Console.WriteLine("You have chosen the Hoenn region");
case "S":
case "s":
Console.WriteLine("You have chosen the Sinoh region");
case "U":
case "u":
Console.WriteLine("You have chosen the Unova region");
break;
case "R":
case "r":
Console.WriteLine("Return");
break;
default:
Console.WriteLine("{0} is not a valid choice", myChoice);
break;
}
Fallthrough only works when the case statement has no body. Since your “h” and “s” cases have code present, you need a
breakafter them.Additionally, as a suggestion: you could do a
String.ToUpper()on yourswitchparameter so you can avoid having to check for both the lowercase and uppercase variants ofmyChoice. Yourswitchstatement then becomes: