1、ArrarList 转换为 string[] :
ArrayList list = new ArrayList();
list.Add("aaa");
list.Add("bbb");
string[] arrString = (string[])list.ToArray(typeof( string)) ;
将ArrayList转化为String数组,我们可以使用
- String[] array = (String[])heightArrayList.toArray();
运行程序报类型转换错误。
解决方式:
- String[] heightArray = (String[]) heightArrayList.toArray(new String[0]);
2、string[] 转换为 ArrarList :
ArrayList list = new ArrayList(new string[] { "aaa", "bbb" });
3、ArrayList 转换为 string :
ArrayList list = new ArrayList();
list.Add("aaa");
list.Add("bbb");
string str= string.Join(",", (string[])list.ToArray(typeof( string)));
4、string 转换为 ArrayList :
string str="1,2,3,4,5";
ArrayList b = new ArrayList( str.Split(',') ) ;
whatever is worth doing is worth doing well...