C# ArrayList 与 string、string[] 的转换

xiaoxiao2021-02-28  3

1、ArrarList 转换为 string[]

  ArrayList list = new ArrayList();

  list.Add("aaa");

  list.Add("bbb");

  //转换成数组

  string[] arrString = (string[])list.ToArray(typeof( string));

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(',') );

转载请注明原文地址: https://www.6miu.com/read-2350165.html

最新回复(0)