First - if you are not on .NET 1.1, you should avoid ArrayList - prefer typed collections like List<T> .
When you say โcopy,โ do you want to replace, add, or create a new one?
To add (using List<T> ):
List<int> foo = new List<int> { 1, 2, 3, 4, 5 }; List<int> bar = new List<int> { 6, 7, 8, 9, 10 }; foo.AddRange(bar);
To replace, add foo.Clear(); before AddRange . Of course, if you know that the second list is long enough, you can fixate on the indexer:
for(int i = 0 ; i < bar.Count ; i++) { foo[i] = bar[i]; }
To create a new one:
List<int> bar = new List<int>(foo);
Marc gravell
source share