C # array deep copy,
The array is deeply copied, that is, a new array is completely copied, and the content of the two arrays is identical.
There are generally four methods:
1. Loop traversal and Replication
2. array member method: CopyTo
The CopyTo method is used to copy all source arrays to the target array. You can specify the starting index of the target array. However, make sure that the target array can accommodate the lower source array. CopyTo can be used to merge multiple arrays.
3. Static Method of Array class: Array. Copy
Array. the Copy method can Copy some elements of the source array to the target array. When there are three parameters, you can specify the number of elements copied from the source array (starting from the first element ); you can specify not only the number of elements copied from the source array and the starting index, but also the starting index of the target array.
4. object class member method: Clone
Since the Clone return value type is object, it must be forcibly converted to int []
// Known array: int [] array = {1, 5, 9, 3, 7, 2, 8, 6, 4}; // (1 ). traverse and copy int [] copy1 = new int [array. length]; for (int I = 0; I <array. length; I ++) {copy1 [I] = array [I];} // (2 ). use the CopyTo method int [] copy2 = new int [array. length]; array. copyTo (copy2, 0); // (3 ). use Array. copy method int [] copy3 = new int [array. length]; Array. copy (array, copy3, array. length); // (4 ). use the Clone method int [] copy4 = (int []) array. clone ();