|
-
September 9th, 2011, 02:00 PM
#1
[RESOLVED] .NET4.0/VS 2010>>Need "Case 0 to 8" without using Fall Thru
Hi!
In VB I can use the Select Case function and specify case 0 to 8, or Case a to b
How can I do this in C# without using fall thru?
Thanks!
-
September 9th, 2011, 02:41 PM
#2
Re: .NET4.0/VS 2010>>Need "Case 0 to 8" without using Fall Thru
Well you can't; without fallthrough it obviously won't work. Your goals are contradictory. You can of course use fallthrough in C# as long as there is no code in any but the last case:
Code:
switch( someVar )
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
DoStuff();
break;
}
However, if it is that trivial then you can just use an if statement:
Code:
if( someVar > 0 && someVar < 9 ) { }
OR, the more expensive and a bit superfluous version...
if( Enumerable.Range( 0, 8 ).Contains( someVar ) ) { }
Last edited by BigEd781; September 9th, 2011 at 02:46 PM.
-
September 9th, 2011, 02:41 PM
#3
Re: .NET4.0/VS 2010>>Need "Case 0 to 8" without using Fall Thru
You can't do it with the switch statement.
You'll need to use another type of construct like an if or if/else statement.
-
September 9th, 2011, 04:02 PM
#4
Re: .NET4.0/VS 2010>>Need "Case 0 to 8" without using Fall Thru
Yeah, I was about half afraid that was the case. I'll use the if statement.
Thanks guys!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|