C# List Count
Description
List
gets the number of elements contained
in the List
Syntax
List.Count
has the following syntax.
public int Count { get; }
Example
List capacity tells us the number of elements a list can have without allocating more memory, while the count tells us the element count in a list.
using System;/* w w w . j a v a 2 s. c o m*/
using System.Collections.Generic;
public class Example
{
public static void Main()
{
List<string> letters = new List<string>();
Console.WriteLine("\nCapacity: {0}", letters.Capacity);
letters.Add("A");
letters.Add("B");
letters.Add("C");
letters.Add("D");
letters.Add("E");
Console.WriteLine("Capacity: {0}", letters.Capacity);
Console.WriteLine("Count: {0}", letters.Count);
}
}
The code above generates the following result.