switch statement
-
Upgraded some code from VB to C#.
Select Case whatever
Case x To y
' mmhmm
Case Is > z
' yeesh
Case Else
' ??
End SelectSo I changed this to:
switch (whatever) {
case x to y:
// mmhmm
break;
case is > z:
// yeesh
break;
default:
// ??
break;
}But, obviously To and Is don't convert. What do I use instead? Do I need to replace it all with
if (x >= whatever >= y)
[update] Forgot to put the closing brace in the code sample.
Ninja (the Nerd)
Confused? You will be... -
Upgraded some code from VB to C#.
Select Case whatever
Case x To y
' mmhmm
Case Is > z
' yeesh
Case Else
' ??
End SelectSo I changed this to:
switch (whatever) {
case x to y:
// mmhmm
break;
case is > z:
// yeesh
break;
default:
// ??
break;
}But, obviously To and Is don't convert. What do I use instead? Do I need to replace it all with
if (x >= whatever >= y)
[update] Forgot to put the closing brace in the code sample.
Ninja (the Nerd)
Confused? You will be...Ninja-the-Nerd wrote:
But, obviously To and Is don't convert. What do I use instead? Do I need to replace it all with if (x >= whatever >= y)
In this case, with only 3 options I would say this is your best bet.
if(whatever > x && whatever < y) { //mmhmm } else if(whatever > z) { // yeesh } else { // ?? }
-
Ninja-the-Nerd wrote:
But, obviously To and Is don't convert. What do I use instead? Do I need to replace it all with if (x >= whatever >= y)
In this case, with only 3 options I would say this is your best bet.
if(whatever > x && whatever < y) { //mmhmm } else if(whatever > z) { // yeesh } else { // ?? }
So it can't be done then? Nuts. Incidentally how do you convert
If searchString Like "p#" Then
I've written a strLeft function to do what VB6 did. It works well enough, I could change it and check forif (functionClass.strLeft(searchString,4) == "page")
. Thanks btw.
Ninja (the Nerd)
Confused? You will be... -
So it can't be done then? Nuts. Incidentally how do you convert
If searchString Like "p#" Then
I've written a strLeft function to do what VB6 did. It works well enough, I could change it and check forif (functionClass.strLeft(searchString,4) == "page")
. Thanks btw.
Ninja (the Nerd)
Confused? You will be...You can use
searchString.StartsWith(p)
-^-^-^-^-^- no risk no funk ................... please vote ------>
-
Upgraded some code from VB to C#.
Select Case whatever
Case x To y
' mmhmm
Case Is > z
' yeesh
Case Else
' ??
End SelectSo I changed this to:
switch (whatever) {
case x to y:
// mmhmm
break;
case is > z:
// yeesh
break;
default:
// ??
break;
}But, obviously To and Is don't convert. What do I use instead? Do I need to replace it all with
if (x >= whatever >= y)
[update] Forgot to put the closing brace in the code sample.
Ninja (the Nerd)
Confused? You will be...C# doesn't have the same concept behind switch statements as VB. It can be done, but you would need to list all of the values between "x" and "y". The "is > z" can't be represented by a case, however. Your best bet would be to do either rework your logic so you can use the switch, which would probably mean defining more specific cases and using the default case to handle the "is > z" condition, or to use if/else blocks.
Scott.
—In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]