Change some value inside the List

前端 未结 7 1396
甜味超标
甜味超标 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:56

    I'd probably go with this (I know its not pure linq), keep a reference to the original list if you want to retain all items, and you should find the updated values are in there:

     foreach (var mc in list.Where(x => x.Name == "height"))  
         mc.Value = 30;
    

提交回复
热议问题