C# Hashtable Hashtable(IDictionary, Single)

Description

Hashtable Hashtable(IDictionary, Single) initializes a new instance of the Hashtable class by copying the elements from the specified dictionary to the new Hashtable object. The new Hashtable object has an initial capacity equal to the number of elements copied, and uses the specified load factor, and the default hash code provider and comparer.

Syntax

Hashtable.Hashtable(IDictionary, Single) has the following syntax.


public Hashtable(
  IDictionary d,
  float loadFactor
)

Parameters

Hashtable.Hashtable(IDictionary, Single) has the following parameters.

  • d - The IDictionary object to copy to a new Hashtable object.
  • loadFactor - A number in the range from 0.1 through 1.0 that is multiplied by the default value which provides the best performance. The result is the maximum ratio of elements to buckets.

Example

The following code example creates hash tables using different Hashtable constructors and demonstrates the differences in the behavior of the hash tables, even if each one contains the same elements.


using System;/* w w w  . j  av  a 2  s  . co m*/
using System.Collections;
using System.Globalization;


public class SamplesHashtable
{
    public static void Main()
    {
        SortedList mySL = new SortedList();
        mySL.Add("FIRST", "Hello");
        mySL.Add("SECOND", "World");
        mySL.Add("THIRD", "!");

        Hashtable myHT1 = new Hashtable(mySL, (float).8);
    }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    System.Collections »




ArrayList
BitArray
Comparer
Hashtable
Queue
SortedList
Stack