Get the number of key/value pairs contained in the Hashtable in CSharp

Description

The following code shows how to get the number of key/value pairs contained in the Hashtable.

Example


using System;//from   w  w  w .  ja  va  2 s.  com
using System.Collections;

class MainClass
{
    public static void Main()
    {
        Hashtable    hash = new Hashtable();
        hash.Add("A", "1");
        hash.Add("B", "2");
        hash.Add("C", "3");
        hash.Add("D", "4");
        hash.Add("E", "5");
        
        Console.WriteLine(hash.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