Swtich statement

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

Guest

I am updating some code that has a switch statement. The code was VB.net and
I using C#.net. The problem is the switch statement is giving me a syntax
error on this line. It doesn't like the case 1,2,3,4. What is the syntax for
this?

case 1,2,3,4:
 
newguy said:
I am updating some code that has a switch statement. The code was VB.net
and
I using C#.net. The problem is the switch statement is giving me a syntax
error on this line. It doesn't like the case 1,2,3,4. What is the syntax
for
this?

case 1,2,3,4:

case 1:
case 2:
case 3:
case 4:
 
I should have said this in my first post. the people that wrote this code
said not to change it. they have case 1,2,3,4 to catch error codes returned
by there app. the same error message applies to all 1,2,3,4. I know I can
break it down like your example and copy the error message but i just wanted
to know how to do it the other way. Thanks for you help.
 
No - my example has only 1 code block, not 4; there is no need for
duplication. The same "// code" section will get run in all 4 cases.

In C#, you can "drop through" a block if and only if you haven't provided
any code. You can't do the C-style cumulative cases, however.

But just put your code where my "// code" is and it will work fine.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top