傲雪凌峰
一个后来者,期待在技术上有所进步。

一、关于深克隆和浅克隆的实现

 Object.MemberwiseClone( )只能实现对象的浅克隆,我们可以实现ICloneable接口的Clone( )来实现对象的深克隆和浅克隆,示例如下:

<1>浅克隆

 

using System;
public class Person : ICloneable
{
    
public object Clone()
    {
        
return this;
    }

    
public string Name { getset; }

    
public string Sex { getset; }

}

 

 

<2>深克隆

 

using System;
public class Person : ICloneable
{
    
public object Clone()
    {
        
return this.MemberwiseClone();
    }

    
public string Name { getset; }

    
public string Sex { getset; }

}
posted on 2008-10-16 00:03  傲雪凌峰  阅读(254)  评论(0)    收藏  举报