【Object.MemberwiseClone】
Creates a shallow copy of the current Object.
protected object MemberwiseClone()
C#的 Object对象中没有Clone()方法,只有MemberwiseClone()。下面是官方给的ShallowCopy、DeepCopy的示例。
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;
}
}
参考:https://msdn.microsoft.com/zh-cn/library/system.object.memberwiseclone(v=vs.110).aspx