Get the number of elements contained in the List in CSharp

Description

The following code shows how to get the number of elements contained in the List.

Example


using System;//w  ww  .j  a v  a  2  s  .com
using System.Collections.Generic;

public class Example
{
    public static void Main()
    {
        List<string> letters = new List<string>();

        letters.Add("A");
        letters.Add("B");
        letters.Add("C");
        letters.Add("D");
        letters.Add("E");

         Console.WriteLine(letters.Count);

    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Collections »




ArrayList
BitArray
Collection
Comparer
HashSet
Hashtable
LinkedList
List
ListDictionary
OrderedDictionary
Queue
SortedList
SortedSet
Stack
StringCollection
StringDictionary