Collections & LINQ · Lesson 13

Paid and unpaid

A bool decides which rows enter the total.

How it works

The first order is paid and its amount is 10.50. The second is paid and its amount is 2.25. The third has an amount of 100 and IsPaid is false, so it stays out. The paid total is 12.75.

A working example

var orders = new[] { new Order("a", 10.50m, true), new Order("b", 2.25m, true), new Order("c", 100m, false) };
var paid = orders.Where(o => o.IsPaid).Sum(o => o.Amount);
Console.WriteLine(paid);

Expected output

12.75
Try this
Try the filter on a smaller list.