I wanted to ask how can I simplify the foreach block below. I tried to do all this in a single linq expression, but I could not figure out how to manipulate the "count" values inside the query.
More on what I'm trying to achieve: - I have a huge list with potential duplicates where Id are repeated, but the "Count" property is different numbers - I want to get rid of duplicates, but still not lose these "Count" values - therefore, for elements with the same identifier, I summarize the "Count" properties
However, the current code does not look very pretty:
var grouped = bigList.GroupBy(c => c.Id).ToList(); foreach (var items in grouped) { var count = 0; items.Each(c=> count += c.Count); items.First().Count = count; } var filtered = grouped.Select(y => y.First());
I do not expect the whole solution, ideas will be also highly appreciated :)
source share