Languages
[Edit]
EN

C# / .NET - get List size

0 points
Created by:
Marcino
720

In this article, we would like to show you how to get List size in C#.

Quick solution:

List<int> myList = new List<int> { 1, 2, 3, 4 };

int size = myList.Count; // 4

 

Practical example

In this example, we use Count property to get the size of myList.

using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        List<int> myList = new List<int> { 1, 2, 3, 4 };

        int size = myList.Count;

        Console.WriteLine(size); // 4
    }
}

Output:

4

References

  1. List<T>.Count Property (System.Collections.Generic) | Microsoft Docs

Alternative titles

  1. C# / .NET - get List length
  2. C# / .NET - List Count property
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join