Collections & LINQ · Lesson 14

Refunds

A negative paid amount is still part of the sum.

How it works

10m is a payment and -3m is a refund. Both are paid, so both enter the sum. 10 + -3 is 7. An unpaid row would stay out. A refund does not stay out just because it is negative.

A working example

var orders = new[] { new Order("a", 10m, true), new Order("b", -3m, true) };
Console.WriteLine(orders.Where(o => o.IsPaid).Sum(o => o.Amount));

Expected output

7
Try this
Try the filter on a smaller list.