如何把一个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 copy到array中; 

 

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

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

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

posted on 2011-05-27 09:24  .net 虾米  阅读(2979)  评论(6)    收藏  举报

导航