assign value using linq

后端 未结 4 1705
孤城傲影
孤城傲影 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:22

    You can create a extension method:

    public static IEnumerable Do(this IEnumerable self, Action action) {
        foreach(var item in self) {
            action(item);
            yield return item;
        }
    }
    

    And then use it in code:

    listofCompany.Do(d=>d.Id = 1);
    listofCompany.Where(d=>d.Name.Contains("Inc")).Do(d=>d.Id = 1);
    

提交回复
热议问题