What is the proper way to convert a char
to int
?
This gives 49
:
int val = Convert.ToInt32('1');
//int val = Int32.Parse("1"); // Works
I don't want to convert to string and then parse it.
I'm surprised nobody has mentioned the static method built right into System.Char
...
int val = (int)Char.GetNumericValue('8');
// val == 8