Why are the lists list1Instance
and p
in the Main
method of the below code pointing to the same collection?
class Person
Return a new instance of Person that is a copy of p
instead of p
itself in Get(). You'll need a method to make a deep-copy of a Person object to do this. This won't make them read only, but they will be different than those in the original list.
public IEnumerable Get()
{
foreach (Person p in l1)
{
yield return p.Clone();
}
}