assign value using linq

后端 未结 4 1723
孤城傲影
孤城傲影 2020-12-07 18:51
public class Company
{
    public int id { get; set; }
    public int Name { get; set; }
}

List listofCompany = new List();

4条回答
  •  悲哀的现实
    2020-12-07 19:36

    Be aware that it only updates the first company it found with company id 1. For multiple

     (from c in listOfCompany where c.id == 1 select c).First().Name = "Whatever Name";
    

    For Multiple updates

     from c in listOfCompany where c.id == 1 select c => {c.Name = "Whatever Name";  return c;}
    

提交回复
热议问题