Difference between the System.Array.CopyTo and System.Array.Clone
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Array.CopyTo and Array.Clone both duplicate array contents, but they solve different problems. Clone creates a new array object with the same length and contents, while CopyTo copies elements into an existing destination array starting at a specified index.
What Clone Does
Clone allocates a new array of the same runtime type and length as the source array, then copies the elements into it.
Because the array object is new, changing cloned[0] does not change the first slot in original.
The important limitation is that Clone performs a shallow copy. If the array contains references to mutable objects, both arrays still point to the same objects.
What CopyTo Does
CopyTo requires a destination array that already exists. It copies the source elements into that destination starting at the index you provide.
Output:
This is useful when you want to copy into part of a larger array or reuse an existing buffer.
The Most Important Difference
The simplest distinction is this:
- '
Clonereturns a new array' - '
CopyTowrites into an array you already have'
That difference affects memory allocation, API shape, and intent. Clone is good when you want a standalone duplicate. CopyTo is good when you control the destination layout.
Both Operations Are Shallow Copies
This matters a lot for reference types.
Both lines print 42 because the array was copied, not the Box instance inside it. The same shallow-copy rule applies to CopyTo.
Exceptions and Constraints
CopyTo will throw if the destination array is too small or if the destination index would cause the copy to run past the end. It also requires type compatibility between source and destination.
Clone avoids those destination-size issues because it always creates the new array for you, but it returns object, so callers typically cast the result back to the expected array type.
In many codebases, Array.Copy is also worth considering because it makes source and destination ranges more explicit.
When to Use Which
Use Clone when:
- you want a new array of the same size
- you want a quick shallow duplicate
- you do not need to choose a destination offset
Use CopyTo when:
- you already have a destination array
- you want to copy into a specific position
- you are managing buffers or partial array placement
The choice is mostly about ownership and destination control, not about deep versus shallow semantics, because both are shallow.
Common Pitfalls
The biggest pitfall is assuming Clone makes deep copies of the objects stored inside the array. It does not.
Another mistake is using CopyTo without allocating enough space in the destination array. That throws at runtime.
A third issue is forgetting that Clone returns object. In strongly typed code, you usually need an explicit cast.
Summary
- '
Clonecreates a new array with copied elements.' - '
CopyTocopies elements into an existing destination array.' - Both operations perform shallow copies.
- Use
Clonefor a quick full duplicate. - Use
CopyTowhen you need placement control or want to reuse an existing buffer.

