in the Programming C# 5 book, I've read that:
As well as the static Copy method, the Array class defines a nonstatic CopyTo method, which copies the entire array into a target array, starting at the specified offset. This method is present because all arrays implement certain collection interfaces, including ICollection (where T is the array’s element type), which defines this CopyTo method. Copy To does not guarantee to handle overlap correctly, and the documen tation recommends using Array.Copy in scenarios where you know you will be dealing with arrays—CopyTo is just for the benefit of general purpose code that can work with any implementation of a collection interface.
It says that overlap won't be handled correctly when using CopyTo non-static method. The problem is that I think no overlap may happen when we are using CopyTo on an array! Because, it is trying to copy entire array to the destination. If the destination is the same as source, destination is the same size as source, hence, the only position we can copy to is 0 ( I mean second argument must be zero: myArray.CopyTo(myArray, 0) ), hence, each element is exactly copied at the index, where it already is. So what is the overlap problem this book is talking about?
All I said can be seen in the code below:
> var a = new int[] { 1, 2, 3 };
> a
int[3] { 1, 2, 3 }
> a.CopyTo(a, 0) // this is the only way I can call this method without
// getting error, If I want to pass the same array as first argument
> a
int[3] { 1, 2, 3 } // nothing went wrong! What is to worry about?
Besides the things I said, why may someone copy an array into itself at index 0? What is the point in doing that? What am I missing?
Note that this is not the same question as this SO post. That SO post is about Copy mehtod, not CopyTo.
I think all considerations around overlapping when working with arrays, only make sense if we pass an array to Copy(). As described in that SO post.