Skip to content

Add AggregateBy examples#12486

Open
mahmoudbakeer wants to merge 1 commit intodotnet:mainfrom
mahmoudbakeer:main
Open

Add AggregateBy examples#12486
mahmoudbakeer wants to merge 1 commit intodotnet:mainfrom
mahmoudbakeer:main

Conversation

@mahmoudbakeer
Copy link
Copy Markdown

@mahmoudbakeer mahmoudbakeer commented Apr 5, 2026

Summary
This PR adds comprehensive usage examples for the new .NET 9 Enumerable.AggregateBy method. These examples are designed to help developers understand the difference between using a constant seed and a seed selector for stateful aggregations.

Examples Added:
Multi-value Aggregation (seedSelector): Demonstrates using a tuple (Total, Count) to compute both the sum and the frequency of elements per group in a single pass.

Simple Summation (seed): Illustrates the use of a constant decimal seed to calculate total values (salaries) grouped by a key (department).

Technical Highlights:
Efficiency: The examples emphasize the benefit of AggregateBy over GroupBy by avoiding the allocation of intermediate grouping collections.

Real-world Context: Uses an Employee class scenario to make the utility of the API immediately clear to developers.

Each example includes input data, the LINQ implementation, and the expected console output.

@mahmoudbakeer mahmoudbakeer requested a review from a team as a code owner April 5, 2026 10:28
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Apr 5, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @dotnet/area-system-linq

@mahmoudbakeer
Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@mahmoudbakeer mahmoudbakeer changed the title Add AggregateBy seedSelector examples Add AggregateBy examples Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Linq community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant