switch case can't have >?

  • Thread starter Thread starter mp
  • Start date Start date
Peter Duniho said:
Correct.

See http://msdn.microsoft.com/en-us/library/06tc147t.aspx

You can use:

Or the much more sensible:

if (case == 0)
{
// something
}
else if (case > 0)
{
// something else
}

C#'s switch statement does not have all the features that VB.NET's does.

Pete

i went with 'if'
i only showed the two cases, but there are actually 3
< = >
which is why i thought 'switch' rather than 'if' until i found 'switch'
doesn't allow comparison other than equality
thanks
mark
 
Rick Lones said:
No, the VB-style expressions are not allowed. If you insist on that
idiom, you could do:

switch (pos.CompareTo(0))
{
case -1:
// < case
break;
case 0:
// = case
break;
case 1:
// > case
break;
}

Only if you don't mind people thinking your code is weird, though.

-rick-

thanks for the info
people would already think my code was weird <g> except no one would want to
look at it :-)
mark
 
Back
Top