Implement the value assignment between the List of two object instances using Linq.

Source: Internet
Author: User

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}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.