Interview Questions

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

C# Interview Questions and Answers


(Continued from previous question...)

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

The first one performs a deep copy of the array, the second one is shallow. A shallow copy of an Array copies only the elements of the Array, whether they are reference types or value types, but it does not copy the objects that the references refer to. The references in the new Array point to the same objects that the references in the original Array point to. In contrast, a deep copy of an Array copies the elements and everything directly or indirectly referenced by the elements.

(Continued on next question...)

Other Interview Questions