Why use Clone()?

后端 未结 3 2075

What is main purpose of using Clone() in C#?

What is the benefit of using it?

3条回答
  •  -上瘾入骨i
    2021-01-05 13:21

    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).

提交回复
热议问题