Copy ExamplesΒΆ

The general syntax for this method is:

Array.Copy(originalArray, copiedArray, numItems)

This method returns a new array with the designated values copied from the original array to an new array.

Example

Create a copy of the array areaCodes.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
int[] areaCodes = new int[] {314, 703, 202, 207, 636};
int[] otherAreaCodes = new int[5];

Array.Copy(areaCodes, otherAreaCodes, 5);

Console.WriteLine(otherAreaCodes[0]);
Console.WriteLine(otherAreaCodes[1]);
Console.WriteLine(otherAreaCodes[2]);
Console.WriteLine(otherAreaCodes[3]);
Console.WriteLine(otherAreaCodes[4]);

Output

314
703
202
207
636