Hi friends,
I want to know that what's the difference between the System.Array.CopyTo() and System.Array.Clone()?
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
pankaj joshiPosted Dec 3, 2012, 3:17 AM
Dorababu MekaPosted Jan 20, 2012, 11:43 PM
with CopyTo() not only does the destination array need to already exist, it needs to be large enough to hold all the elements in the source array from the index you specify as the destination.
check here for example
http://geekswithblogs.net/dforhan/archive/2005/12/01/61852.aspx
you can also refer to msdn
http://msdn.microsoft.com/en-us/library/system.array.clone.aspx
http://msdn.microsoft.com/en-us/library/system.array.copyto.aspx
Satyapriya NayakPosted Jan 20, 2012, 11:31 PM
The first one performs a deep copy of the array, the second one is shallow.
The CopyTo() method copies the elements into another existing array.The Clone() method returns a new array (a shallow copy) object containing all the elements in the original array.
Thanks