Select Case
Select Case number
Case Is = 0
a = 1
Case Is <= 50
a = 2
Case Is <= 100
a = 3
Case Is <= 200
a = 4
How do i achieve the equivalent in c#?![]()
Select Case number
Case Is = 0
a = 1
Case Is <= 50
a = 2
Case Is <= 100
a = 3
Case Is <= 200
a = 4
How do i achieve the equivalent in c#?![]()
In C# swicth statement is used to do this but its not flexible enough to provide you more than one check as you are doing in above code in VB6
C# switch statement is:
switch(number)
{
case 0: //Exact 0
// your code
break;
case 1: //Exact 1
// your code
break;
defaul: //Any other value than above cases
// your code
break;
}
So here is no cushsion of <= or >= it just supports = that's it.
To achieve the task from If else logic, do the following:
int a = 0;
if(number == 0)
a = 1;
else if(number <= 50)
a = 2;
else if(number <=100)
a = 3;
else if(number <=200)
a = 4;
Cheers ;-)