Clone() Vs CopyTo() Array

The Clone() method returns a new array object containing all the elements in the original array. This method creates a copy of an array as an object, therefore needs to be cast to the actual array type before it can be used to do very much. The clone is of the same Type as the original Array.

The CopyTo() method copies the elements into another existing array. It copies the elements of one array to another pre-existing array starting from a given index (usually 0).

Both perform a shallow copy . Shallow copying is creating a new object and then copying the non static fields of the current object to the new object. If the field is a value type, a bit by bit copy of the field is performed. If the field is a reference type, the reference is copied but the referred object is not, therefore the original object and its clone refer to the same object. A shallow copy of an object is a new object whose instance variables are identical to the old object.
 (C) 2022    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About