Mid LINQ

How to calculate running totals using LINQ?

How to calculate running totals using LINQ?

var salaries = employees.Select(e => e.Salary).ToList();

double runningTotal = 0;

var runningTotals = salaries.Select(s => runningTotal += s);

foreach (var total in runningTotals)

Console.WriteLine(total);

Explanation:

Accumulates sums as you iterate through the sequence.

More from LINQ Tutorial

All questions for this course