|
-
Sep 13th, 2013, 12:43 PM
#1
Swtch Statement
In VB.Net, I would write my Select Case as
Code:
Dim sid As Integer = 0
sid = 41
Select Case sid
Case 33 To 60
End Select
How do I do that in C#
I tried using this convertor
It gave me
Code:
switch (sid) {
case 33: // TODO: to 60
break;
}
which obviously is not what I want...
I was referring to this link
So in c# do I have to write it as
Code:
switch (sid)
{
case 33: case 34: case 35: case 36: case 37: case 38: case 39: case 40:
case 41: case 42: case 43: case 44: case 45: case 46: case 47: case 48:
case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56:
case 57: case 58: case 59: case 60:
break;
}
If yes, then what if there are 100 values to check (1 To 100)? Do I have to write Case 100 times? Or is there a better way to write it?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 13th, 2013, 02:00 PM
#2
Re: Swtch Statement
As far as I know, it is not possible in C#, you would have to do case 1: case 2: case 3:, etc.
If you have large ranges, using an if statement would be the better option.
-
Sep 13th, 2013, 02:03 PM
#3
Re: Swtch Statement
Boy! If that's true then By Jove!!!! My love for VB just increased even more!!!!! 
I will wait for more responses before I close this thread...
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Sep 13th, 2013, 05:18 PM
#4
Re: Swtch Statement
'Select Case' and 'switch' in C# are totally different constructs.
Your VB example is an if/else block in C#:
Code:
if (sid >= 33 && sid <= 60)
{
}
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
|