Blog

Difference between System.Array.CopyTo() and system.Array.clone()

Posted by Yogesh Sharma Blogs | C# Language Dec 07, 2012
Difference between System.Array.CopyTo() and system.Array.clone().
Difference between System.Array.CopyTo() and system.Array.clone().

system.Array.Clone()-

Clone() will return an object (Which holds the shallow copy of the array). 

System.Array.CopyTo()-

The CopyTo() method copies the elements into another existing array.

Example-

//Here is one string array-
string[] names = new string[] {"Yogesh","Walam","Raj","Sandy" };
//This is new atring array with same size of previous             
string[] copyNames = new string[names.Length];
names.CopyTo(copyNames,0);
string[] clone;
clone = names.Clone() as string[];
COMMENT USING
PREMIUM SPONSORS
Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.
Employers - Post Free Jobs
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.
Employers - Post Free Jobs