Select Case

In VB6 i have this:

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#?

[276 byte] By [Kripz] at [2007-12-24]
# 1
if (number == 0)
a = 1;
else if (number <= 50)
a = 2;
else if (number <= 100)
a = 3;
else if (number <= 200)
a = 4;
else
a = the value that you forgot in the case you posted above ;)

MatthewWatson at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2
ah dam, im going to be here for a while, over 100 conditions to check :(
Kripz at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3

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 ;-)

RizwanSharp at 2007-10-8 > top of Msdn Tech,Visual C#,Visual C# Language...