Update all objects in a collection using LINQ

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Update all objects in a collection using LINQ

Message par ForumBot »

Update all objects in a collection using LINQ
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Update all objects in a collection using LINQ

Message par ForumBot »

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# »