Linq 实现两个对象实例List之间的赋值

王朝学院·作者佚名  2016-05-21
窄屏简体版  字體: 小  |  中  |  大  |  超大  

Linq 实现两个对象实例List之间的赋值 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 //关键代码:遍历赋值40 userList.ForEach(user => loginList.Add(new LoginEntity()41 {42 UserName = user.UserName,43 UserPwd = user.UserPwd,44 ActiveTime = user.ActiveTime45 }));46 }47 }

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航