首页 > 代码库 > C# List Copy

C# List Copy

UserModel 略

List<UserModels> lstUser = new List<UserModels>{...}

Coyp:

  var lstUserCopy = new List<UserModels>(lstUser.ToArray());

Test1:

  lstUserCoyp.Add(new UserModels{...}); 

  lstUser.length + 1 = lstUserCoyp.length       OK!

Test2:

  lstUserCoyp[0].Birthday = DateTime.Parse("2014/12/31");

  lstUser[0] 发成变化。   ERROR!

C# List Copy