What?s the difference between the System.Array.CopyTo() and
System.Array.Clone()?
Answers were Sorted based on User's Feedback
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 |
Answer / satish
System.Array.CopyTo() performs the deep copy that is it
creates a new duplicate copy without effect of old one.
Whereas Clone creates as shallow copy but as it is a clone
so it is linked with the old one so affect whenever changes
occures in the old one.
| Is This Answer Correct ? | 1 Yes | 2 No |
Answer / rahul
The first one performs a deep copy of the array, the second
one is shallow.
| Is This Answer Correct ? | 0 Yes | 3 No |
What basic steps are needed to display a simple report in crystal?
What is the xml document structure?
How does the XmlSerializer work ?
What is use of hashtable in c#?
Write code for palindrome?
Define c# i/o classes? List the commonly used classes?
What language is arduino?
Is goto statement supported in c#?
What is difference between === and ==?
Illustrate the differences between the system.array.copyto() and system.array.clone()?
How do you inherit a class into other class in c#?
You have got 1 million parking slots. At a time a parking slot can be free or not. To get next slot easily which data structure to implement?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)