C# ArrayList Count

Description

ArrayList Count gets the number of elements actually contained in the ArrayList.

Syntax

ArrayList.Count has the following syntax.


public virtual int Count { get; }

Example

Gets the number of elements actually contained in the ArrayList.


using System; //from w w w . j  av a2  s.c o  m
using System.Collections; 
 
class MainClass { 
  public static void Main() { 
    ArrayList al = new ArrayList(); 
     
    Console.WriteLine("Initial number of elements: " + al.Count); 
 
    Console.WriteLine("Adding 6 elements"); 
    // Add elements to the array list 
    al.Add('C'); 
    al.Add('A'); 
    al.Add('E'); 
    al.Add('B'); 
    al.Add('D'); 
    al.Add('F'); 
 
    Console.WriteLine("Number of elements: " + al.Count); 
  }
} 

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack