In C# if an object in a list is added to another list, does changing the object in the second list change the same object in the first list?

前端 未结 2 1268
无人及你
无人及你 2021-01-24 13:01

Say I have a list of Person objects (List) called persons, like this:

class Person
{
    public int PersonId         


        
2条回答
  •  Happy的楠姐
    2021-01-24 13:07

    Since Person is a reference type (class) changing name on the item in the list will change the name on the Person object and all references to that object will now see the new name. If it was a struct that would not be the case.

提交回复
热议问题