Use List<int> to sum values.
Ready — edit the code above and click Run.
using System;
using System.Collections.Generic;
class Program {
static void Main() {
var list = new List<int> { 1, 2, 3, 4 };
int sum = 0;
foreach (var x in list) sum += x;
Console.WriteLine(sum);
}
}
Try solving on your own first, then reveal the official answer.
List