Collections & LINQ · Lesson 1

Lists of values

A list is a sequence you can walk from the first item to the last.

How it works

prices holds 3, then 5, then 8. The first index is 0, so prices[0] prints 3. Sum visits 3, then 5, then 8 and prints 16. Nothing in this sample removes an item. The list you start with is the list Sum sees.

A working example

var prices = new[] { 3m, 5m, 8m };
Console.WriteLine(prices[0]);
Console.WriteLine(prices.Sum());

Expected output

3
16
Try this
Start with the whole list.