Update all objects in a collection using LINQ
While you can use a ForEach
extension method, if you want to use just the framework you can do
collection.Select(c => {c.PropertyToSet = value; return c;}).ToList();
The ToList
is needed in order to evaluate the select immediately due to lazy evaluation.
collection.ToList().ForEach(c => c.PropertyToSet = value);
I am doing this
Collection.All(c => { c.needsChange = value; return true; });