© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
4 replies
cheeze2000

Aggregate data grouped by a key

I'm looking to aggregate these data:
// from this
[
  new { id = 1, qty = 3 },
  new { id = 2, qty = 5 },
  new { id = 1, qty = 10 },
]

// to this
[
  new { id = 1, qty = 13 },
  new { id = 2, qty = 5 },
]
// from this
[
  new { id = 1, qty = 3 },
  new { id = 2, qty = 5 },
  new { id = 1, qty = 10 },
]

// to this
[
  new { id = 1, qty = 13 },
  new { id = 2, qty = 5 },
]

my current approach iterates over the list into a dictionary and check for duplicate keys. i have a feeling it can be done in a cleaner way with System.Linq stuff
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Aggregate Group By Functions on Items
C#CC# / help
3y ago
system.aggregate Exception
C#CC# / help
2y ago
❔ Write an Aggregate
C#CC# / help
4y ago