原代码:
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();