将ArrayList复制到另一个ArrayList [英] Copying an ArrayList to another ArrayList
本文介绍了将ArrayList复制到另一个ArrayList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好!
我想知道是否有另一种方法可以将ArrayList复制到另一个而不使用foreach循环。
我试过这个:
Hi everyone!
I want to know if there's another way to copy an ArrayList to another without using a foreach loop.
I tried this:
MyOldArraylist = new ArrayList(MyNewArraylist);
它有效,但我不知道这是不是一个好主意。
先谢谢!
It works, but i don't know if its a good idea or not doing this.
Thanks beforehead!
推荐答案
看看这个:
http://msdn.microsoft.com/en-us/library/system.array.copy.aspx [ ^ ]
您好,您可以参考此代码将一个数组列表复制到c#
Hi you can refer this code for copying one array list to another in c#
System.Collections.ArrayList OriginalArrList = new System.Collections.ArrayList();
System.Collections.ArrayList CopyArrayList = new System.Collections.ArrayList();
OriginalArrList.Add("1234");
OriginalArrList.Add("123");
OriginalArrList.Add("12");
OriginalArrList.Add("1");
OriginalArrList.Add("xyz");
CopyArrayList.Add(OriginalArrList.Clone());
你可以达到文章:
http://www.authorcode.com/code-sample-copy-one-arraylist-to-another-arraylist-in-c/
问候,
mubin
You can reach to article:
http://www.authorcode.com/code-sample-copy-one-arraylist-to-another-arraylist-in-c/
Regards,
mubin
我认为你的方法是正确的方法之一。
我向您展示了一种不同的方法,例如:
I think your approach is one of the right one.
I show you a different approach like:
OriginalArrList = new System.Collections.ArrayList();
CopyArrayList = new System.Collections.ArrayList();
OriginalArrList.Add("1234");
OriginalArrList.Add("123");
OriginalArrList.Add("12");
OriginalArrList.Add("1");
OriginalArrList.Add("xyz");
CopyArrayList.Add(OriginalArrList.Clone());
或,
Or,
ArrayList a = new ArrayList();
ArrayList b = new ArrayList();
b.AddRange(a);
这篇关于将ArrayList复制到另一个ArrayList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文