ArrayList CopyTo() method with starting index
How to copy ArrayList to a compatible Array, starting at the specified index of the array
C# Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
class Program { static void Main(string[] args) { ArrayList colors = new ArrayList() { "GreenYellow", "LightBlue", "Plum" }; Console.WriteLine("ArrayList Elements...."); foreach (string color in colors) { Console.WriteLine(color); } string[] colorArray = { "PaleVioletRed", "PeachPuff", "Peru", "Snow", "Sienna" }; Console.WriteLine("Array Elements..."); foreach (string color in colorArray) { Console.WriteLine(color); } colors.CopyTo(colorArray, 1); Console.WriteLine("\nAfter Call CopyTo(Array, Int32) Method; Array Elements..."); foreach (string color in colorArray) { Console.WriteLine(color); } Console.ReadLine(); } } |
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
ArrayList Elements.... GreenYellow LightBlue Plum Array Elements... PaleVioletRed PeachPuff Peru Snow Sienna After Call CopyTo(Array, Int32) Method; Array Elements... PaleVioletRed GreenYellow LightBlue Plum Sienna |