.Net - Frequently Asked Questions
Difference between System.Array.CopyTo and System.Array.Clone()
The System.Array.CopyTo method copies the elements into another pre-existing array starting from a given index. In this case the destination array need to already exist. More over, the target Object needs to be sufficient to hold all the elements in the source array from the index you specify as the destination. When perform CopyTo() method both arrays must be single dimensional.
The System.Array.Clone() method returns a new array object, which means that the destination array need not exist yet since a new one is created from scratch with containing all the elements in the original array. The Clone() method works on both single and multi-dimensional arrays.
Performance wise System.Array.CopyTo is faster than Clone when copying to array of same type.
Shallow copy and Deep copy
In .Net Shallow copy and deep copy are used for copying data between objects. 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. While Deep copy is creating a new object and then copying the non-static fields of the current object to the new object. If a field is a value type, a bit by bit copy of the field is performed. More about... Difference between Shallow copy and Deep copy
Arrays are using for store similar data types grouping as a single unit. We can access Array elements by its numeric index. The array indexes start at zero. More about.... Array