日期:2014-05-18  浏览次数:20898 次

求救,字符串数组转换为整形数组
int[] arr = new int[ch.Length];
for(int i = 0; i < ch.Length; i++)
{
  arr[i] = int.Parse(ch[i]);
}
int[] arr = new int[ch.Length];
for(int i = 0; i < ch.Length; i++)
{
  arr[i] = Convert.ToInt(ch[i].ToString());
}
这些我都同过了,还是不行,网上说行的我都试。 为什么就算不行呢?求指教55555555

------解决方案--------------------
可能有部分字符串不是合法的整数格式字符串,所以转不了。

假定默认不合法的转换成0,这样试试:
int[] arr = new int[ch.Length];
for(int i = 0; i < ch.Length; i++)
{
int.TryParse(ch[i],out arr[i]);
}