c# equivalent to select case true

B

Brendan Green

Show us a code sample in VB what you want to do.

As a guess, you're not talking about the switch keyword, are you?
 
G

Guest

In VB, you are able to do this since the case statements can include a wide
range of expressions. In C#, the case expressions must be constant, so the
usefulness of this technique is greatly reduced.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB.NET to C# Converter
Instant VB: C# to VB.NET Converter
Instant J#: VB.NET to J# Converter
Clear VB: Cleans up outdated VB.NET code
 
T

TS

thanks, yes i am looking for a
switch(true)
{
case var1 = 5 : ...
case var9 = 21: ...

i guess you can't do it as i thought
 
B

Bruce Wood

No, you can't do this in C#. Other languages have this kind of switch
construct:

switch (value)
{
case expression:
case expression:
...
default:
}

C# (as well as C, C++, and Java) has this kind of switch construct:

switch (expression)
{
case constant:
case constant:
case constant:
...
default:
}

So, no. You have to use if... else if... else if... else.
 
C

Christof Nordiek

TS said:
thanks, yes i am looking for a
switch(true)
{
case var1 = 5 : ...
case var9 = 21: ...

i guess you can't do it as i thought
<snip>
you can:
the c# equivalent is:

if (var1 == 5)
{
.....
}
else if (var9 == 21)
{
......
}
........
 
T

TS

thank you all, thats what i thought!


Christof Nordiek said:
<snip>
you can:
the c# equivalent is:

if (var1 == 5)
{
.....
}
else if (var9 == 21)
{
......
}
.......
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top