Deep Copy with Array

前端 未结 4 961
孤街浪徒
孤街浪徒 2021-01-19 19:06

Why doesn\'t ICloneable\'s Clone method return a deep copy?

Here is some sample code:

class A : ICloneable 
{
    public int          


        
4条回答
  •  无人共我
    2021-01-19 19:47

    Array.Copy copies the values of the array, in this case, references. There is nothing in the documentation of Array.Copy() that indicates a check for classes that implement IClonable and call Clone() instead. You will need to loop through the array and call Clone() yourself.

    BTW, yes, IClonable kind of sucks.

提交回复
热议问题