public class Emplyee:ICloneable
{
        private string _name = string.Empty;
    private int _id = 0;
    private string _email = string.Empty;
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }
    public int Id
    {
        get { return _id; }
        set { _id = value; }
    }
    public string Email
    {
        get { return _email; }
        set { _email = value; }
    }

    public object Clone()
    {
        return this.MemberwiseClone();
    }

    public Emplyee()
    {
    }

    public Emplyee(Emplyee e)
    {
        this._id = e.Id;
        this._name = e.Name;
        this._email = e.Email;
    }
}

public class Company : ICloneable
{
    private Emplyee _e = null;
    public Emplyee E
    {
        get { return _e; }
        set { _e = value; }
    }
    private string _name = string.Empty;
    public string Name
    {
        get { return _name; }
        set { _name = value; }
    }

    public object Clone()
    {
        Company c = (Company)this.MemberwiseClone();
        c._e = new Emplyee( this._e );
        return c;
    }
}

   public void Main()
{
     Company c1 = new Company();

      c1.E = new Emplyee();
        c1.E.Id = 0;
        c1.E.Email = "x@163.com";
        c1.E.Name = "aaa";
      Company c2 = (Company )c1.Clone();
}

相关文章:

  • 2022-12-23
  • 2021-11-07
  • 2021-08-31
  • 2022-12-23
  • 2021-05-21
  • 2022-01-09
  • 2022-12-23
  • 2021-10-01
猜你喜欢
  • 2021-06-05
  • 2022-01-20
  • 2021-06-01
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-02
相关资源
相似解决方案