Change some value inside the List

前端 未结 7 1360
甜味超标
甜味超标 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<TSource>(this IEnumerable<TSource> outer, Action<TSource> updator)
            {
                foreach (var item in outer)
                {
                    updator(item);
                }
            }
    
    list.Where(w => w.Name == "height").ToList().Update(u => u.height = 30);
    
    
    0 讨论(0)
提交回复
热议问题