I've recently took over a project as a personal hobby in a challenge to improve my code quality. I had made this method but I feel like I'm definitely over working it in some way, I feel like there's a really simple way to do it without having to run through a large switch like this??
I know the 0-9 could just be .ToString()
'd and then parsed to int and returned, but I'm unsure how to merge that idea whilst also considering the rest of the switch cases.
public static short ParseHeight(char input)
{
switch (input)
{
case '0':
return 0;
case '1':
return 1;
case '2':
return 2;
case '3':
return 3;
case '4':
return 4;
case '5':
return 5;
case '6':
return 6;
case '7':
return 7;
case '8':
return 8;
case '9':
return 9;
case 'a':
return 10;
case 'b':
return 11;
case 'c':
return 12;
case 'd':
return 13;
case 'e':
return 14;
case 'f':
return 15;
case 'g':
return 16;
case 'h':
return 17;
case 'i':
return 18;
case 'j':
return 19;
case 'k':
return 20;
case 'l':
return 21;
case 'm':
return 22;
case 'n':
return 23;
case 'o':
return 24;
case 'p':
return 25;
case 'q':
return 26;
case 'r':
return 27;
case 's':
return 28;
case 't':
return 29;
case 'u':
return 30;
case 'v':
return 31;
case 'w':
return 32;
default:
throw new FormatException("The input was not in a correct format: input must be between (0-k)");
}
}