switch matter fallthrough c#?


switch matter fallthrough personal vital reasons regretful switch vs. if/else if constructs. an instance method here:



static twine numbertowords(int number)
{
string[] numbers = new string[]
{ "", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine" };
string[] tens = new string[]
{ "", "", "twenty", "thirty", "forty", "fifty",
"sixty", "seventy", "eighty", "ninety" };
string[] teenagers = new string[]
{ "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen",
"sixteen", "seventeen", "eighteen", "nineteen" };

twine ans = "";
switch (number.tostring().length)
{
box 3:
ans += string.format("{0} hundred ", numbers[number / 100]);
box 2:
int t = (number / 10) % 10;
(t == 1)
{
ans += teens[number % 10];
break;
}
else (t > 1)
ans += string.format("{0}-", tens[t]);
box 1:
int o = array % 10;
ans += numbers[o];

break;
default:
pitch new argumentexception("number");
}
relapse ans;
}


the intelligent deferential since string[]s should announced outmost function: well, are, only an example.



the compiler fails following error:




control can't tumble by box tag ('case 3:') another
control can't tumble by box tag ('case 2:') another


why? there any proceed arrange intrepidity but carrying 3 ifs?



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members