大神,下面这道题怎么做....浅度复制和深度复制的区别?有下列Car类和Tyre类,实现ICloneable接口的Clone方法,完成Car类的深度复制public class Car:ICloneable
    {
        public double Speed { get; set; }
        public string Color{ get; set; }
        public Tyre CarTyre{ get; set; }        public object Clone()
        {
//填入代码
        }
    }    public class Tyre
{
        public string Type { get; set; }
        public double Size { get; set; }        public Tyre (string type, double size)
        {
            Type = type;
            Size = size;
        }
    }

解决方案 »

  1.   

    baidu google下呗,多的是大神们解释过了.........
      

  2.   

    http://www.cnblogs.com/zhiji6/archive/2012/07/27/2611477.html
      

  3.   

    http://blog.csdn.net/atskyline/article/details/6189747
      

  4.   

    public class Car:ICloneable
    {
     object ICloneable.Clone()
     {
       return new Car{Tyre =new Tyre{     Type =this.CarTyre.Type,
                Size = this.CarTyre.Size;}
     }
     public Car Clone()
     {
       return ((ICloneable)this).Clone() as Car;
     }
    }
    ps:建议这里显示实现接口而不是直接实现接口,同时提供一个更为友好的方法供外边使用(public Car Clone())
      

  5.   

    public object Clone()
            {
                  return new Car{Speed=this.Speed,Color=this.Color,CarTyre=new Tyre(this.CarTyre.Type,this.CarTyre.Size)};
            }