C# Foundations · Lesson 7

Arrays

new[] stores values in order, and the first index is 0.

How it works

The array holds 12, then 8, then 25. prices[0] is 12, prices[1] is 8, and prices[2] is 25. Length is 3. Sum walks every item and prints 45. The array does not grow when you read it.

A working example

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

Expected output

12
45
Try this
Every item in this array is a decimal.