Phương thức MemberwiseClone() tạo một shadow copy bằng cách tạo một đối tượng mới, sau đó sao chép các thuộc tính non-static của đối tượng hiện tại sang đối tượng mới.
public class Person
{
public int Age;
public string Name;
public IdInfo IdInfo;
public Person ShallowCopy()
{
return (Person)this.MemberwiseClone();
}
public Person DeepCopy()
{
Person other = (Person)this.MemberwiseClone();
other.IdInfo = new IdInfo(IdInfo.IdNumber);
other.Name = String.Copy(Name);
return other;
}
}