The following code seems to add a new record to the list but overwrites all the record with the last record created. I can get it to work fine with ...
lpr.Add(new personRecord(){Age = pr.Age,Name = pr.Name});
but this seems more long winded and in the real app the record is much bigger.
private void button1_Click(object sender, EventArgs e)
{
personRecord pr = new personRecord();
List<personRecord> lpr = new List<personRecord>();
pr.Age = 40;
pr.Name = "Bob";
lpr.Add(pr);
pr.Age = 30;
pr.Name = "Steve";
lpr.Add(pr);
pr.Age = 44;
pr.Name = "Phil";
lpr.Add(pr);
pr.Age = 33;
pr.Name = "Sue";
lpr.Add(pr);
}
public class personRecord
{
private int age;
private string name;
public int Age
{
get { return age; }
set { age = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
}