Why use Clone()?

后端 未结 3 2102

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

What is the benefit of using it?

3条回答
  •  没有蜡笔的小新
    2021-01-05 13:01

    When we copy the contents of an object to another (SomeClass obj2 = obj1), obj2 also belonging to the same class, modifying the content of obj2 will also modify the content of obj1. This is because they are reference types. Using Clone() (in a proper manner) can avoid this. On modifying a cloned object , the original will not get modified.

提交回复
热议问题