For ScoreOption, I expect to get the following input "A", "B", and T_(state) for example T_NY
How can I write a case switch statement for the third option T_(state)?
switch(ScoreOption.ToUpper().Trim())
{
case "A":
....
break;
case "B":
....
break;
case T_????
....
break;
}
I might as well write if-else statement?
string s = ScoreOption.ToUpper().Trim();
switch(s)
{
case "A":
....
break;
case "B":
....
break;
default:
if (s.StartsWith("T_"))
{
....
}
break;
}
You can't have a variable as a case in a switch statement. You'll have to do something like
case "T_NY":
case "T_OH":
break;
etc.
Now what you could do is
switch (ScoreOption.ToUpper().Trim())
{
case "A":
break;
case "B":
break;
default:
//catch all the T_ items here. provided that you have specifed all other
//scenarios above the default option.
break;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With