Blog
157   0

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

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.

Latest Blogs