๐ WAYPOINT LESSON
Aggregation and the statement
โญ beginnerโณ 13 min read๐ Lesson 84 of 85
LINQ folds a list of transactions into balances, category totals, and the monthly statement.
Balances and totals
decimal balance = ledger.Sum(t => t.Dir == Direction.Income ? t.Amount : -t.Amount);
var byCategory = ledger
.GroupBy(t => t.Category)
.Select(g => new { Category = g.Key, Total = g.Sum(t => t.Amount) })
.OrderByDescending(x => x.Total)
.ToList();
The signed fold gives the running balance; the GroupBy pipeline is the category report. Both are one pass over data โ the aggregation lesson's patterns applied to a real domain.
The statement
A monthly statement composes them: filter the month, compute income/expense/balance, find the biggest category, take the top 3 entries by amount descending. Nothing new โ Module 15's Where/Sum/GroupBy/OrderByDescending in combination, which is the point: capstones verify that earlier modules became reflexes.
โก Now practice
Ready to CodeCapstone workshopThe ledger's milestones as graded challenges: validate, aggregate, categorize, filter โ plus the File-based CSV persistence from the plan's milestone 5.
4 challenges ยท ยท ~50 min