|
-
Aug 19th, 2005, 04:36 AM
#1
Thread Starter
Hyperactive Member
Switch Statement **SOLVED**
Hey all,
this is really emberassing
I want to use a switch statement to check for some Integer values
Code:
switch (x)
{
case 0:
doSomething();
break;
case 1:
doSomethingElse();
default:
doNothing();
break;
}
This is working. But is there a way that I can have more than one Integer inside my case Statement?
Like
Code:
switch (x)
{
case 0,1,2:
doSomething();
break;
case 2,3,4:
doSomethingElse();
default:
doNothing();
break;
}
Thanks for the help!
Stephan
Last edited by Sgt-Peppa; Aug 19th, 2005 at 07:22 AM.
Reason: SOLVED
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Aug 19th, 2005, 06:51 AM
#2
Re: Switch Statement
Something like this?
Code:
switch (myInt)
{
case 1:
case 2:
case 3:
Console.WriteLine("Your number is {0}.", myInt);
break;
default:
Console.WriteLine("Your number {0} is not between 1 and 3.", myInt);
break;
}
- ØØ -
-
Aug 19th, 2005, 07:21 AM
#3
Thread Starter
Hyperactive Member
Re: Switch Statement
Yes, that does the trick! I did not know you could have the code "fall" through! It works, thanks!
Stephan
Keep Smiling - even if its hard 
Frankie Says Relax, wossname Says Yeah!
wossname:--Currently I'm wearing a gimp suit and a parachute.
C# - Base64 Blog
-
Aug 19th, 2005, 03:03 PM
#4
Re: Switch Statement **SOLVED**
Yes you can. Don't think you can have ranges like case10-20, but it should really be possible. Maybe it is though...but I am to tired to look it up...
- ØØ -
-
Aug 21st, 2005, 06:10 PM
#5
Re: Switch Statement **SOLVED**
sadly though, it looks like the control can only fall through if you don't have any line of code in the case block. I was looking for a fix of this before.
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
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
|