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 : LoginEntity
11     {
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.Now
25             },
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.ActiveTime
45         }));
46     }
47 }

 

posted @ 2015-05-29 15:49  KenmuHuang  阅读(5648)  评论(2编辑  收藏  举报
如果您看完本篇博文,觉得对您有所收获,请点击右下角的 [推荐]
如果您想转载,请注明出处(原创内容,请尊重个人劳动成果)
如果您有任何意见或建议,欢迎留言
感谢您的阅读,敬请关注我的后续博客文章