The known quantity group is as follows:
Int[] Array = {1, 5, 9, 3, 7, 2, 8, 6, 4};
(1). Reference replication, easy to cause errors, not recommended
int[] Copy = array;
(2). Traverse Copy
int[] copy = new Int[array. Length];
for (int i = 0; i < array.length; i++)
{
Copy[i] = Array[i];
}
(3). Using the CopyTo method
int[] copy = new Int[array. Length];
Array. CopyTo (copy, 0);
The CopyTo method is used as a copy of the source array to the destination array, you can specify the starting index of the target array, but you need to ensure that the destination array can hold the source array, CopyTo can be used to merge multiple arrays
(4). Using the Array.copy method
int[] copy = new Int[array. Length];
Array.copy (array, Copy, array. Length);
The Array.copy method can copy some elements of the source array into the target array, three parameters, you can specify the number of elements copied from the source array (starting with the first element), and the five parameters can specify the number of elements copied from the source array and the starting index, or the starting index of the target array.
(5). Using the Clone method
Int[] copy= (int[]) array. Clone ();
Because the return value type of clone is object, cast to int[]
Several methods of C # copy array