Why are the lists list1Instance
and p
in the Main
method of the below code pointing to the same collection?
class Person
If your person object is a real object then you should consider using an immutable version.
public class Person
{
public FirstName {get; private set;}
public LastName {get; private set;}
public Person(firstName, lastName)
{
FirstName = firstName;
LastName = lastName;
}
}
In this way its not possible to change the content of the instance once created and therefore it isn't important that existing instances are reused in multiple lists.