Change some value inside the List

前端 未结 7 1395
甜味超标
甜味超标 2020-12-07 22:23

I have some list (where T is a custom class, and class has some properties). I would like to know how to change one or more values inside of it by using Lambda Expressions,

7条回答
  •  醉话见心
    2020-12-07 22:57

    I know this is an old post but, I've always used an updater extension method:

          public static void Update(this IEnumerable outer, Action updator)
            {
                foreach (var item in outer)
                {
                    updator(item);
                }
            }
    
    list.Where(w => w.Name == "height").ToList().Update(u => u.height = 30);
    
    

提交回复
热议问题