select case question

  • Thread starter Thread starter Starbuck
  • Start date Start date
S

Starbuck

Hi

I am converting a app from VB6 to C# and I was wondering if anyone can tell
me how to implement the following in c#
case 207 To 252

Thanks in advance
 
Hi Starbuck,

You can use an if/else if/else statement, similar to this:

if (val >= 0 && val <= 206)
{
// your code
}
else if (val >= 207 && val <= 252)
{
}
//...more else ifs
else
{
// when nothing else matches
}

Joe
 
You could also do this:

switch (val) {
case 207:
case 208:
case 209:
// ... more cases here
case 252:
// your code here
// break;
}

Obviously it's not terribly practical for a range of that many cases, and
if/elseif ... /else would be more sensible. But the above works for those
times when you have a handful of cases that need to run the same code.

--Bob
 
Thanks guys



Bob Grommes said:
You could also do this:

switch (val) {
case 207:
case 208:
case 209:
// ... more cases here
case 252:
// your code here
// break;
}

Obviously it's not terribly practical for a range of that many cases, and
if/elseif ... /else would be more sensible. But the above works for those
times when you have a handful of cases that need to run the same code.

--Bob
 
Back
Top