将ArrayList转换为Arrry时出错 [英] Error while converting ArrayList to Arrry
本文介绍了将ArrayList转换为Arrry时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在一段代码中我需要将数组列表转换为整数数组。
但我收到此错误..
至少有一个元素在源数组无法转换为目标数组类型。
这是我的代码。
in a piece of code i need to convert array list to Array of integers.
But i am getting this error..
"At least one element in the source array could not be cast down to the destination array type."
Here is my code.
ArrayList mylist = new ArrayList();
In32[] arrToReturn = null;
String[] arr = mystring.Split(',');
foreach (String value in arr)
list.Add(value);
arrToReturn = (int[])mylist.ToArray(typeof(Int32));
请帮忙。
Please help.
推荐答案
改变这个line
list.Add(value); to list.Add(Convert.ToInt32(value));
Change this line
list.Add(value); to list.Add(Convert.ToInt32(value));
这篇关于将ArrayList转换为Arrry时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文