C# Foundations · Lesson 8

Lists

A list starts empty and grows when you add items.

How it works

List<decimal> is a collection you can Add to. The sample adds 4, then 6. Count is 2 and Sum is 10. An array is enough when the lesson already knows every value. A list is the one to pick when the program discovers values one at a time.

A working example

var prices = new List<decimal>();
prices.Add(4m);
prices.Add(6m);
Console.WriteLine(prices.Sum());

Expected output

10
Try this
Add the values before you sum them.