Linq改进

原代码:

  foreach (var item in pageData)
            {
                list.Add(new tn_Manager { UserName = item.UserName, IsAudit = item.IsAudit, CreateTime = item.CreateTime, RoleName = PublicQuery.GetRoleById(item.RoleId).Name });
            }

改进之后:

var list = pageData.Select(item => new tn_Manager {UserName = item.UserName, IsAudit = item.IsAudit, CreateTime = item.CreateTime, RoleName = PublicQuery.GetRoleById(item.RoleId).Name}).ToList();

  

转载于:https://www.cnblogs.com/axu92312/p/9671330.html

你可能感兴趣的:(Linq改进)