15,881,027 members
See more:
hi everyone
how i can use switch like this code

```case n is
when 0 =>
Put_Line ("You typed zero");
when 1 | 9 =>
Put_Line ("n is a perfect square");
when 2 =>
Put_Line ("n is a prime number");
Put_Line ("n is an even number");
when 3 | 5 | 7 =>
Put_Line ("n is a prime number");
when 4 =>
Put_Line ("n is a perfect square");
Put_Line ("n is an even number");
when 6 | 8 =>
Put_Line ("n is an even number");
end case;```

so how i can write switch by c# like this code

i want
```int x=10;
switch (x)
{
case 1 | x<2: // i  want check x if < 2 and > 20 ok
Console.Write("1");
break;
case (2) :
Console.Write("1");
break;
case(22):
Console.Write("2");
break;
}```
this code give me error
in case 1 | x<2
thnx for any help
Posted
Updated 29-Oct-10 20:22pm
v2

## Solution 3

```switch(x)
{
case 0:
Console.Write("You typed zero");
break;
case 1 :
case 9 :
Console.Write("n is a perfect square");
break;
case 2 :
Console.Write("n is a prime number");
Console.Write("n is an even number");
break;
case 3:
case 5:
case 7:
Console.Write("n is a prime number");
break;
case 4 :
Console.Write("n is a perfect square");
Console.Write("n is an even number");
break;
case 6 :
case 8 :
Console.Write("n is an even number");
break;
}```

```int x=10;

switch (x)
{
case 2 :
Console.Write("1");
break;
case 22:
Console.Write("2");
break;
}
if(x<2 || x>20) // i want check x if < 2 and > 20 ok
Console.Write("1");```

i want check x if < 2 and > 20
it is not possible but x is < 2 Or x > 20 is possible.
there is no number that is less than 2 and gather than 20.

## Solution 1

I think You Can Simply Use if else statements... It will be easy.

XML
```case 1
if x<2 and x>20 then // i want check x if < 2 and > 20 ok
Console.Write("1");
end if
break;```