System.Collections.Hashtable.CopyTo Method

Copies the Hashtable elements to a one-dimensional Array instance at the specified index.

Syntax

public virtual void CopyTo (Array array, int arrayIndex)

Parameters

array
The one-dimensional Array that is the destination of the DictionaryEntry objects copied from Hashtable. The Array must have zero-based indexing.
arrayIndex
The zero-based index in array at which copying begins.

Exceptions

TypeReason
ArgumentNullException array is null.
ArgumentOutOfRangeException arrayIndex < 0.
ArgumentException

array has more than one dimension.

-or-

arrayIndex > array.Length - The Hashtable.Count of the current instance.

InvalidCastExceptionThe type of the current instance is not assignment-compatible with the type of array.

Remarks

The elements are copied to the Array in the same order in which the enumerator iterates through the Hashtable.

To copy only the keys in the Hashtable, use Hashtable.Keys.CopyTo.

To copy only the values in the Hashtable, use Hashtable.Values.CopyTo.

This method is an O(n) operation, where n is Hashtable.Count.

Requirements

Namespace: System.Collections
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0