r/badcode • • Nov 13 '20

java Getting Digits using Switch Catch

Post image
881 Upvotes

52 comments sorted by

View all comments

3

u/hhellloo Nov 13 '20

I think this is better.

public static int evalDigit(string x)
{
 int result = Convert.ToInt32(x);
 if(result > 9 || result < 0)
 {
   result = -1;
 }
return result;
}

Edit: Oh, it is in Java, I thought it was c#

2

u/Chroniaro Nov 13 '20

Pretty sure this would still compile in C#, but the camelCase method name and capital S in String kinda give it away