score:3

LINQ is a technology to query sources, not to modify them. So you should not use a query and change something in this query. Instead you can filter what you need to modify and then use a loop to actually apply the changes.

IEnumerable<User> usersWithSmallFiles = users
    .Where(u => u.Files.Any(f => f.Size <= 10));

foreach (User u in usersWithSmallFiles)
    u.Files = u.Files.Where(f => f.Size > 10).ToList();

You also can't use RemoveAll on IEnumerable<T>, it's a List<T>-method. That's why you have used ToList() in the query. But on this way you create a new list which is not related to your Files-list, it just contains the same files but the collection is different, so RemoveAll is pointless.


Related Query

More Query from same tag