[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!
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 ) ) { }
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.
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!