c# - Trying to learn better lambda coding -


while following code works fine wondering if there cleaner way accomplish lambda expressions?

var counter = 1;  foreach (var item in model) {    item.id = counter++; } 

you make inline lambda foreach

model.foreach(x => x.id = counter++); 

update/restriction:

  • this work when model type list<>
  • in case of value types items won't updated - without error

Comments