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");


There are 10 elements in the list

Free Spring Boot Tutorial - 5 Hours Full Course

Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course