C#C
C#2y ago
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 },
]

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
Was this page helpful?