+ 10

What’s the difference between the System.Array.CopyTo() and System.Array.Clone() ?

20th May 2018, 7:55 AM
Prabhat
Prabhat - avatar
2 Answers
+ 8
The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array. The CopyTo()method copies the elements into another existing array. Both perform a shallow copy. A shallow copy means the contents (each array element) contains references to the same object as the elements in the original array. A deep copy (which neither of these methods performs) would create a new instance of each element's object, resulting in a different, yet identical object https://stackoverflow.com/questions/198496/difference-between-the-system-array-copyto-and-system-array-clone
20th May 2018, 8:03 AM
᠌᠌Code X
᠌᠌Code X - avatar
+ 2
Clone is your cloning the existing array as it is, so its same reference. CopyTo is cloning the array but then moving it.
21st May 2018, 5:02 PM
Apple Blossom
Apple Blossom - avatar