Should I provide a deep clone when implementing ICloneable?

前端 未结 3 1133
终归单人心
终归单人心 2021-01-12 23:51

It is unclear to me from the MSDN documentation if I should provide a deep or a shallow clone when implementing ICloneable. What is the preferred option?

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-13 00:15

    Short answer: Yes.

    Long Answer: Don't use ICloneable. That is because .Clone isn't defined as being a shallow or a deep clone. You should implement your own IClone interface, and describe how the clone should work.

提交回复
热议问题