Easy csharp

List — add and sum #49

Problem

Use List<int> to sum values.

Hints
  • new List<int> { ... }

Your practice code

Ready — edit the code above and click Run.

Solution

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.

Explanation

List is the default dynamic array in C#.

Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details