如何把一个Array 复制到ArrayList中?

 string[] array = new string[]{" 1", "2"," 3", "4"," 5" };

 ArrayList list = new ArrayList();
一:使用for循环,将array数组中的数据逐步加入到ArrayList的对象中;

 //1、for循环
            for (int i = 0; i < array.Length;i++)
            {
                 list.Add(array[i]);
            }

二:使用ArrayList 的CopyTo()方法:

 //2、copyTo()
            list.CopyTo(array);

三:使用ArrayList的Adapter()方法:

 //3.Adapter()
            ArrayList list1=ArrayList.Adapter(array);
四:直接使用构造方法传入,因为Array实现了ICollection:

 //4\构造方法
            ArrayList list3 = new ArrayList(array);

相关文章:

  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2021-07-26
猜你喜欢
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案