Create Hashtable with specified initial capacity in CSharp

Description

The following code shows how to create Hashtable with specified initial capacity.

Example


using System.Collections;
public class SamplesHashtable
{/*from ww w  .  j  a v a2  s . co  m*/

    public static void Main()
    {
        Hashtable myHT1 = new Hashtable(3);
        myHT1.Add("FIRST", "Hello");
        myHT1.Add("SECOND", "World");
        myHT1.Add("THIRD", "!");

        foreach (string firstName in myHT1.Keys)
        {
            System.Console.WriteLine("{0} {1}", firstName, myHT1[firstName]);
        }
    }
}

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