如何在C#中将ArrayList转换为字符串数组(string )
如何在C#中将ArrayList
转换为string[]
?
string[] myArray = (string[])myarrayList.ToArray(typeof(string));
一个简单的谷歌或MSDN上的搜索就可以做到。 这里:
ArrayList myAL = new ArrayList(); // Add stuff to the ArrayList. String[] myArr = (String[]) myAL.ToArray( typeof( string ) );
尝试使用ToArray()
方法。
ArrayList a= new ArrayList(); //your ArrayList object var array=(String[])a.ToArray(typeof(string)); // your array!!!
using System.Linq; public static string[] Convert(this ArrayList items) { return items == null ? null : items.Cast
使用.ToArray(类型)
string[] stringArray = (string[])arrayList.ToArray(typeof(string));
您可以使用ArrayList对象的CopyTo方法。
假设我们有一个arraylist,它有String Type作为Elements。
strArrayList.CopyTo(strArray)
另一种方式如下。
上述就是C#学习教程:如何在C#中将ArrayList转换为字符串数组(string )分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
System.Collections.ArrayList al = new System.Collections.ArrayList(); al.Add("1"); al.Add("2"); al.Add("3"); string[] asArr = new string[al.Count]; al.CopyTo(asArr);
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/984936.html