Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

What?s the difference between the System.Array.CopyTo() and
System.Array.Clone()?

Answer Posted / sudhir sheoran

First of all both perform a shallow copy.
Difference is that:-

copy to() needs another array and index from which it starts copy elements of source array to destination array. E.g if destination array B[] has already 3 elements so we can pass 4 as index and B as destination array. This will make it more clear -

class CopyTO
{
public static void Main()
{
int[] A = new int[3];

int [] B = new int[7];
A[0] = 1;
A[1] = 2;
A[2] = 3;

B[0] = 4;
B[1] = 5;

A.CopyTo(B, 4);
for (int i = 0; i < B.Length; i++)
{
Console.WriteLine(B[i]);
}
}
}

The output will be 4,5,0,0,1,2,3 // It copied elements of A
from Index 4 in B.

Clone to return a array that contains elements of the source array. Its length is same as of source array.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

if a base class has a number of overloaded constructors, and an inheriting class has a number of overloaded constructors; can you enforce a call from an inherited constructor to a specific base constructor?

985


Explain the difference between “constant” and “read-only” variables used in c#?

968


How do I edit a dll file?

824


What is serializable in c#?

859


Describe an interface class?

999


What's different between c# and c/c++?

887


in object oriented programming, how would you describe encapsulation?

967


Can abstract class have constructor?

815


What's new in c#?

848


What is the difference between first and firstordefault?

860


What is the Signification of the "new " keyword in C#? example

876


Are c# strings null terminated?

967


How do you read an Excel sheet in C#?

935


Does c# support try-catch-finally blocks?

815


Define an abstract class?

858