Beginner Switch Statement Question

G

Guest

In VB I can have a switch statement with a

Case 1 to 5

in C# it seems I have to have
Case 1:
Case 2:
Case 3:
Case 4:
Case 5:

is there a short cut in C# similar to the VB to have multiple cases handled
by the one result?
 
C

Carlos J. Quintero [VB MVP]

No, the "to" clause is not supported in C#.
--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio .NET, VB6, VB5 and VBA
You can code, design and document much faster.
Free resources for add-in developers:
http://www.mztools.com
 
C

Christof Nordiek

matthew custer said:
In VB I can have a switch statement with a

Case 1 to 5

in C# it seems I have to have
Case 1:
Case 2:
Case 3:
Case 4:
Case 5:

is there a short cut in C# similar to the VB to have multiple cases
handled
by the one result?
It's not possible with the switch-statement in C#.
You could use if-statement instead:
if (switchExpression >= 0 & switchExpression <= 5)
//Case 1 to 5
;
else if (switchExpression = ...)
//Next Case
;
 

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

Top