I have a list of type Person. When I create the list of people it replaces the previous list element\'s information with the current one. I have read about this being the proble
You need to move the initialization of
Person tempPerson = new Person();
into the loop
string[] personArray;
List<Person> people = new List<Person>();
foreach (string line in lines)//lines are the people from file, it is correct
{
personArray = line.Split(',');
if (personArray.Length == 2)
{
Person tempPerson = new Person();
tempPerson.Name = personArray[0];
tempPerson.Address = personArray[1];
people.Add(tempPerson);
}
}
Otherwise you are changing the properties of the same object.