Hi friends,
I want to know that what's the difference between the System.Array.CopyTo() and System.Array.Clone()?
Difference between CopyTo() and Clone() in C#
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Jan 20, 2012, 6:31 PM EST
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
Dorababu MekaRank #457 · 5.5K reputationPosted Jan 20, 2012, 6:43 PM EST
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
pankaj joshi2 reputationPosted Dec 2, 2012, 10:17 PM EST