What is main purpose of using Clone() in C#?
What is the benefit of using it?
Clone()
usually provides a shallow copy of an object (e.g., see Array.Clone() ), it copies the references but not the referenced objects.
It's handy if you understand its limitations, mainly that the semantics of what actually gets copied over into the new object are mostly left to the implementer of the Clone()
method, because the interface ICloneable that defines the Clone()
method is under-specified (so it could be a shallow copy or a deep copy, but you can't rely on either).