SafeDictionaryTKey, TValueCopyTo Method |
Copies the System.Collections.Hashtable elements to a one-dimensional System.Array instance at the specified index.
Namespace: CMS.BaseAssembly: CMS.Base (in CMS.Base.dll) Version: 10.0.0
Syntax public override void CopyTo(
Array array,
int arrayIndex
)
Parameters
- array
- Type: SystemArray
The one-dimensional System.Array that is the destination of the System.Collections.DictionaryEntry objects copied from System.Collections.Hashtable. The System.Array must have zero-based indexing. - arrayIndex
- Type: SystemInt32
The zero-based index in array at which copying begins.
Implements
ICollectionCopyTo(Array, Int32)Remarks
The array has to be large enough to accommodate all the dictionary entries. Unless the dictionary has a fixed number of entries
(or the entries count is limited somehow and the limit is a known number), you should perform the array allocation in a thread-safe way.
Examples
Use the following code snippet to ensure the proper array size.
lock (dictionary.SyncRoot)
{
Array destinationArray = GetArrayOfSize(dictionary.Count);
dictionary.CopyTo(destinationArray, 0);
}
See Also