Why does copy of the List still change properties in the original List using C#

后端 未结 6 1671
不知归路
不知归路 2021-01-21 02:49

Lets say I have this class

public class Employee
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public bool isActive {          


        
6条回答
  •  梦毁少年i
    2021-01-21 03:44

    Why does change in the isActive property of EmployeesCopy also modify the original list?|

    Because both the list point to the same instance of the Employee object. You need to deep copy your Employee object as well.

提交回复
热议问题