Implement the value assignment between the List of two object instances using Linq.
1 public class UserCopy 2 {3 public class LoginEntity 4 {5 public string UserName {get; set;} 6 public string UserPwd {get; set;} 7 public DateTime ActiveTime {get; set;} 8} 9 10 public class UserEntity: LoginEntity11 {12 public string UserID {get; set;} 13 public Int16 UserSex {get; set;} 14 public Int32 UserAge {get; set;} 15} 16 17 protected void UserCopy () 18 {19 List <UserEntity> userList = new List <UserEntity> () {20 new UserEntity () {21 UserID = "U1", 22 UserName = "U1", 23 UserPwd = "U1PWD", 24 ActiveTime = DateTime. now25}, 26 new UserEntity () {27 UserID = "U2", 28 UserName = "U2", 29 UserPwd = "U2PWD", 30 ActiveTime = DateTime. now}, 31 new UserEntity () {32 UserID = "U2", 33 UserName = "U2", 34 UserPwd = "U2PWD", 35 ActiveTime = DateTime. now} 36 }; 37 38 List <LoginEntity> loginList = new List <LoginEntity> (); 39 // key code: traverse and assign a value of 40 userList. forEach (user => loginList. add (new LoginEntity () 41 {42 UserName = user. userName, 43 UserPwd = user. userPwd, 44 ActiveTime = user. activeTime45}); 46} 47}