I would like to know in C# or VB.NET how to use the CopyTo
method of an ArrayList
object to copy its contents to other ArrayList (not a simple Array).
Note: I'm not looking for anything else like the Clone
method of the ArrayList or other sugestions, I need to use the CopyTo
method to know whether I should discard a problem in other situation.
This is a code example in VB.NET:
Dim ArrayList1 as New ArrayList
Dim ArrayList2 as New ArrayList
ArrayList1.Add({"test-Item1-1", "test-Item1-2", "Test-Item1-3"})
' This says that the matrix of the destiny Array is too short.
ArrayList1.CopyTo(ArrayList2.ToArray)
' This shows the typical CastIterator exception 'cause LINQ.
ArrayList1.CopyTo(ArrayList2.Cast(Of Array))
' This says that the ArrayList can't be converted to an Array.
ArrayList1.CopyTo(CType(ArrayList2, Array))