Home > DeveloperSection > Forums > What is the purpose of Clone() in C#?
Takeshi Okada
Takeshi Okada

Total Post:89

Posted on    July-27-2013 8:17 AM

 C# C# 

 1 Reply(s)
 1264  View(s)
Rate this:
Hi Expert!
 i did not understand, what is the purpose of Clon() method in  objects cloning;
thanks in advance!

shreesh chandra shukla
shreesh chandra shukla

Total Post:105

Posted on    July-31-2013 12:57 AM


In object cloning you can create new same copy of object of same class type. The invoking object without knowing the type in advance.

For example:

void Test(ICloneable original)


    var myCloned = original.Clone();


Here cloned is of the same runtime type as original, and you did not need to know what that type was to perform the cloning.

However the usefulness of ICloneable is pretty much none, because it does not define the semantics of the clone operation: is it a shallow copy or a deep copy? Since the interface does not mandate one or the other, you can't really know what you are getting back. And since knowing that is essential because you need to handle the clone accordingly, ICloneable itself is pretty much a burned card.

Don't want to miss updates? Please click the below button!

Follow MindStick