什么是正确的方式转换成一个字符
到 INT
?
这给 49
:
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.
我很惊讶没有人提到的内置到 System.Char
...
I'm surprised nobody has mentioned the static method built right into System.Char
...
int val = (int)Char.GetNumericValue('8');
// val == 8