problem with expressions in switch statement
-
Hi, I want to write the exact replica of this in c# Case 100 To 199 Return "One Hundred " & NumberToText(n Mod 100) Case 200 To 999 Return "NumberToText" after trying this in c#: switch (n) { case (n==0): return ""; case (n>0 && n<20) : return "ada" } i get an error please suggest a way out
-
Hi, I want to write the exact replica of this in c# Case 100 To 199 Return "One Hundred " & NumberToText(n Mod 100) Case 200 To 999 Return "NumberToText" after trying this in c#: switch (n) { case (n==0): return ""; case (n>0 && n<20) : return "ada" } i get an error please suggest a way out
switch (n) { case (n==0): return ""; case (n>0 && n<20) : return "ada"**;** }
It's not that you're just missing a semi-colon there is it... -
switch (n) { case (n==0): return ""; case (n>0 && n<20) : return "ada"**;** }
It's not that you're just missing a semi-colon there is it... -
Hi, switch (n) { case (n==0): return ""; case (n>0 && n<20) : return "ada"; } gives the folowing error cannot convert bool to int
You get that error message because you have a bool expression in the case statement. You can't have expressions in the case statement, only constants. You can only have distinct values, not ranges.
switch (n) {
case 0: return string.Empty;
case 1: return "one";
case 2: return "two"
default: return "other";
}If you want to use ranges, you have to use if statements instead. --- b { font-weight: normal; }
-
Hi, I want to write the exact replica of this in c# Case 100 To 199 Return "One Hundred " & NumberToText(n Mod 100) Case 200 To 999 Return "NumberToText" after trying this in c#: switch (n) { case (n==0): return ""; case (n>0 && n<20) : return "ada" } i get an error please suggest a way out