C# Copy Objects

Date: 2020-02-19
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;
	}
}
34590cookie-checkC# Copy Objects