public class Person { public int Age; public DateTime BirthDate; public string Name; public ExtraInfo ExtraInfo; public Person ShallowCopy() { return (Person) this.MemberwiseClone(); } public Person DeepCopy() { Person clone = (Person) this.MemberwiseClone(); clone.ExtraInfo = new ExtraInfo(ExtraInfo.IdNumber); clone.Name = String.Copy(Name); return clone; } } public class ExtraInfo { public int IdNumber; public ExtraInfo(int idNumber) { this.IdNumber = idNumber; } }
345900cookie-checkC# Copy Objects