Linq操作list


https://www.cnblogs.com/dullfish/p/6101912.html
List<string> existCode = new List<string> { "27101210", "27101220", "27101230", "27101911", "27101921", "27101922", "27101929", "27101991", "27101992", "27101993", "27101999" }; List<string> getCode = new List<string> { "27101210", "27101220" }; var exp1 = existCode.Where(n => getCode.Exists(t => n.Contains(t))).ToList();//查询的list存在固定组里的值 俩个list比较
linq基础查询
var query = from r in p where r.Age == "20" orderby r.Age descending select r;

foreach (Person st in query)
{
Console.WriteLine("***************");
Console.WriteLine("姓名:" + st.Name);
Console.WriteLine("班级:" + st.Sex);
Console.WriteLine("年龄:" + st.Age);
}


 

  • 联合查询-join

//查询出集合qSt中year等于集合qSc中year的元素并形成新的集合
var qjoin = from r in qSt
join c in qSc
on r.year equals c.year
select new
{
Year = r.year,
stName = r.name,
scName = c.name
};

//////循环赋值

List<CopActList> actListModel = _copActListService.GetList(innerNo, iEFlag, appUser.CurrentCorpInfo.Site);

actListModel.ForEach(x => {
x.IEFlag = iEFlag;
});

 

 

查询赋值给对象

var list = getEmsNoListResult.Data.Select(x => new FieldCodeName
{
Code = x.EmsNo,
Name = x.Flag,
Text = x.EmsNo
}).ToList();
if (list != null && list.Count > 0)
{
m.Success = true;
m.Data = list;
}

 

 

posted @ 2021-06-30 14:00  饮水思源^0^  阅读(152)  评论(0编辑  收藏  举报