Collections & LINQ · Lesson 5

Project a field

Select turns each item into the value you want to add.

How it works

Select reads one field and leaves the rest behind. Each order becomes its Amount: 10, 4, and 2. Sum then adds those amounts and prints 16. The original orders are still orders. The query's result is a sequence of decimals.

A working example

var orders = new[] { new Order("a", 10m, true), new Order("b", 4m, true), new Order("c", 2m, false) };
var amounts = orders.Select(o => o.Amount);
Console.WriteLine(amounts.Sum());

Expected output

16
Try this
Try the filter on a smaller list.