Why are the lists list1Instance
and p
in the Main
method of the below code pointing to the same collection?
class Person
IEnumerable
is readonly
p
is a new collection which doesn't depend on list1instance
.
The mistake you made, is that you thought that this line
list[0].FirstName = "uf1";
would only modify one of the lists, when on fact you're modifying the Person
object.
The two collections are distinct, they just happen to have the same items.
To prove that they are different, try adding and removing items from one of the lists, and you'll see that the other one isn't affected.