C# List count elements

This source code example counts the number of elements in the list.

With the Count property, we get the number of elements in the list.

C# List count elements

using System;
using System.Collections.Generic;

class ListExample {
  static void Main(String[] args) {
    var vals = new List<int> { 0, 1, 2, 3, 4, 5,6,7,8,9 };

    Console.WriteLine($"There are {vals.Count} elements in the list");
  }
}

Output:

There are 10 elements in the list

Comments