-
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?
-
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.
-
Re: Swtch Statement
Boy! If that's true then By Jove!!!! My love for VB just increased even more!!!!! :p
I will wait for more responses before I close this thread...
-
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)
{
}