You can also use a method or the IClonable Interface to clone your data.
I prefere my own method with a clear name (shallow or deep clone):
public sealed class Employer
{
public int IDNumber { get; set; }
public DateTime RegDate { get; set; }
public List<BioData> BioInfo { get; set; }
public Employer DeepClone()
{
Employer loClone = new Employer()
{
IDNumber = this.IDNumber,
RegDate = this.RegDate
};
if (this.BioInfo != null)
loClone.BioInfo = this.BioInfo.Select(item => item.DeepClone()).ToList();
return loClone;
}
}
public sealed class BioData
{
public int IndexID { get; set; }
public string Description { get; set; }
public int Age { get; set; }
public double Salary { get; set; }
public BioData DeepClone()
{
//Can also use here
//return this.MemberwiseClone() as BioData;
return new BioData()
{
IndexID = this.IndexID,
Description = String.Copy(this.Description),
Age = this.Age,
Salary = this.Salary
};
}
}
UPDATE
To copy the entries from an existing list in the same list, you can use LINQ.
(ToList
is necessary):
List<Employer> loList = new List<Employer>();
loList.ToList().ForEach(item => loList.Add(item.DeepClone()));