C# 如何将 string[] 转换为 ArrayList?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1701788/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to convert string[] to ArrayList?
提问by Sergey
I have an array of strings. How can I convert it to System.Collections.ArrayList?
我有一个字符串数组。如何将其转换为 System.Collections.ArrayList?
采纳答案by Kyle B.
string[] myStringArray = new string[2];
myStringArray[0] = "G";
myStringArray[1] = "L";
ArrayList myArrayList = new ArrayList();
myArrayList.AddRange(myStringArray);
回答by jthg
Just use ArrayList's constructor:
只需使用 ArrayList 的构造函数:
var a = new string[100];
var b = new ArrayList(a);
回答by IordanTanev
System.Collections.ArrayList list = new System.Collections.ArrayList( new string[] { "a", "b", "c" } );
System.Collections.ArrayList list = new System.Collections.ArrayList( new string[] { "a", "b", "c" } );
回答by Tokar
public stringList[] = {"one", "two", "three"};
public ArrayList myArrayList;
myArrayList = new ArrayList();
foreach (string i in stringList)
{
myArrayList.Add(i);
}