需要知道方法 Convert.ToInt32() 的这种行为的原因
static void Main(string[] args)
{
long a = 12345678912345;
string str = a.ToString();
char[] chars = str.ToCharArray(5, 7);
//result is: 6 7 8 9 1 2 3
int[] ints= new int[chars.Length];
for (int i = 0; i < chars.Length; i++)
{
ints[i] = Convert.ToInt32(chars[i]);
}
//result is: 54 55 56 57 49 50 51
int[] arr = new int[str.Length];
for (int i = 0; i < str.Length; i++)
{
arr[i] = Convert.ToInt32(str[i]);
}
// result is: 49 50 51 52 53 54 55 56 57 49 50 51 52 53
}
那么,为什么当我尝试将 char 转换为 int 时,我得到数字的 unicode 十进制代码? 如果我想得到一个整数,我应该怎么做?
我希望得到整数格式的数字