【发布时间】:2013-11-11 13:20:09
【问题描述】:
我有这些数组
char[] array = {'1', '2', '3', '4'};
int[] sequence = new int[array.Length];
有没有一种简单的方法可以将array 中的数字分配给sequence?
我试过了
for (int i = 0; i < array.Length; i++)
{
seqence[i] = Convert.ToInt32(array[i]);
}
但我得到的是 1、2、3、4 的 ASCII 编码,而不是数字本身。
【问题讨论】:
-
尝试将字符串中的数字从“1”更改为“1”,依此类推。这应该改变它,以便它们变为整数。
-
But I get the ASCII coding of 1,2,3,4 not the numbers themselves。实际上,你得到的是 Unicode 字符的 32 位有符号整数。
标签: c# arrays char int type-conversion