© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
Dyad

❔ Aggregate Group By Functions on Items

```
var items = new [] {
new Item { Year = 2021, Quarter = "Q1", Collection = "Modern", Price = 10 },
new Item { Year = 2021, Quarter = "Q2", Collection = "Antique", Price = 20 },
new Item { Year = 2021, Quarter = "Q3", Collection = "Modern", Price = 30 },
new Item { Year = 2021, Quarter = "Q4", Collection = "Modern", Price = 40 },
new Item { Year = 2022, Quarter = "Q1", Collection = "Antique", Price = 50 },
new Item { Year = 2022, Quarter = "Q2", Collection = "Modern", Price = 60 },
...
}

var groupBys = new []{ x => x.Year, x => x.Quarter, x => x.Collection }

//How to do this part?
//Or is there a better way?
var result = groupBys.Aggregate(items, (accumulator, groupBy) => accumulator.GroupBy(groupBy))
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 data grouped by a key
C#CC# / help
2y ago
Group dictionary by values(?)
C#CC# / help
4y ago
❔ Combine two arrays by alternating items?
C#CC# / help
3y ago
system.aggregate Exception
C#CC# / help
2y ago