alternate if

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,
is there another way to say the following (seems too wordy)

prefix == "TXT" || prefix == "DRP" || prefix == "LBL" || prefix == "CHK" ||
prefix == "UPD" || prefix == "UPC"

thanks,
rodchar
 
hey all,
is there another way to say the following (seems too wordy)

prefix == "TXT" || prefix == "DRP" || prefix == "LBL" || prefix == "CHK"
||
prefix == "UPD" || prefix == "UPC"

switch (prefix)
{
case "TXT" :
case "DRP" :
case "LBL" :
case "CHK" :
case "UPD" :
case "UPC" :
{
// do something
break;
}
default :
{
// for any other case
break;
}
}

Also, remember that C# is case-sensitive, so if prefix is "txt", it will
fall through to the default section...
 
Have to admit I've not tried recently but all the documentation indicates
that you still can't do case statement fall throughs - even in the article
that you link to it states:

Unlike the C++ switch statement, C# does not support an explicit fall
through from one case label to another. If you want, you can use goto a
switch-case, or goto default.
 
I don't believe that it's any change.

You can't to a fall through from one case to another when it contains
code, but you can make a fall through when there is no code in the case.
 
Back
Top