Search This Blog

Monday, February 3, 2014

Difference between Clone() and Copy() method C#

C# > String > Clone and Copy

Clone will copy the structure of a data 
Copy will copy the complete structure and data.

Example:
Difference between Clone() and Copy() method

string[] arr1 = { "a", "b", "c" };
string[] arr2 = arr1; //copy
string[] arr3 = (string[])arr1.Clone();
arr2[0] = "x";
MessageBox.Show(arr1[0] + "," + arr2[0] + "," + arr3[0]);