Update all objects in a collection using LINQ

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Update all objects in a collection using LINQ

Message par Clippy »

Update all objects in a collection using LINQ
Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

Re: Update all objects in a collection using LINQ

Message par Clippy »

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*.
Répondre

Revenir à « .NET & C# »