Dictionary<TKey,TValue>.ICollection.CopyTo(Array, Int32) Dictionary<TKey,TValue>.ICollection.CopyTo(Array, Int32) Method


从指定的数组索引开始,将 ICollection<T> 中的元素复制到一个数组中。Copies the elements of the ICollection<T> to an array, starting at the specified array index.

 virtual void System.Collections.ICollection.CopyTo(Array ^ array, int index) = System::Collections::ICollection::CopyTo;
void ICollection.CopyTo (Array array, int index);


Array Array

一维数组,用作从 ICollection<T> 复制的元素的目标位置。The one-dimensional array that is the destination of the elements copied from ICollection<T>. 该数组的索引必须从零开始。The array must have zero-based indexing.

Int32 Int32

array 中从零开始的索引,从此处开始复制。The zero-based index in array at which copying begins.



arraynullarray is null.

index 小于 0。index is less than 0.

array 是多维的。array is multidimensional.

- 或 --or- array 没有从零开始的索引。array does not have zero-based indexing.

-or- ICollection<T> 中的元素个数大于从 index 到目标 array 末尾之间的可用空间。The number of elements in the source ICollection<T> is greater than the available space from index to the end of the destination array.

- 或 --or- 无法自动将源 ICollection<T> 的类型转换为目标 array 的类型。The type of the source ICollection<T> cannot be cast automatically to the type of the destination array.


从复制的Dictionary<TKey,TValue>每个元素都KeyValuePair<TKey,TValue>是一个表示值及其键的结构。Each element copied from a Dictionary<TKey,TValue> is a KeyValuePair<TKey,TValue> structure representing a value and its key.


如果ICollection源的类型不能自动强制转换为目标array的类型ICollection.CopyTo ,则引发InvalidCastException的非泛型实现,而泛型实现将引发ArgumentExceptionIf the type of the source ICollection cannot be cast automatically to the type of the destination array, the nongeneric implementations of ICollection.CopyTo throw an InvalidCastException, whereas the generic implementations throw an ArgumentException.

此方法是 O (n)运算,其中nCountThis method is an O(n) operation, where n is Count.