Suddenly learned, so put on the blog to share, right when it is a study diary it.
First of all, the array is a reference type, so be careful not to copy the address when copying and not copy the value Oh!
In fact, when copying arrays, be sure to use new in the heap to open a new space dedicated to storing arrays, so that is effective.
(1)
Int[] Pins = {9, 3, 7, 2}; Int[] Copy=new int[pins.length]; for (int i = 0; i < copy.length; i++) { Copy[i] = pins[i]; }
(2)
int[] copy = new int[pins. Length]; Pins. CopyTo (copy, 0);
(3)
Int[] pins= new int[4]{9,3,7,2}; Int[] Alias=pins;
Note that this copy is just a reference, but the address of the data is passed to the alias array, so it is not recommended to copy the array in this way;
(4)
Array.copy (pins,copy,copy. Length)
(5)
Int[] copy= (int[]) pins. Clone ();
This explains why the coercion type conversion of int[] is used because the result type of clone is object, so it needs to be cast to int[]
The object class is actually the base class for all of our classes.
The above this C # copy array of several methods (summary) is the small part to share the whole content of everyone, hope to give you a reference, but also hope that we support topic.alibabacloud.com.