Collection.ICollection.CopyTo(Array, Int32) Collection.ICollection.CopyTo(Array, Int32) Method

定义

从特定的 Collection 索引开始,将 Array 的元素复制到一个 Array 中。Copies the elements of the Collection to an Array, starting at a particular Array index.

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

参数

array
Array Array

一维 Array,它是从 Collection 对象复制的元素的目标。The one-dimensional Array that is the destination of the elements copied from Collection object. Array 必须具有从零开始的索引。The Array must have zero-based indexing.

index
Int32 Int32

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

异常

arraynullarray is null.

index 小于零。index is less than zero.

array 是多维的。array is multidimensional.

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

无法自动将源 Collection 对象的类型强制转换为目标 array 的类型。The type of the source Collection object cannot be cast automatically to the type of the destination array.

注解

Array按枚举器循环访问Collection对象的相同顺序将元素复制到中。The elements are copied to the Array in the same order in which the enumerator iterates through the Collection object.

此方法是 O (n)运算,其中nICollection.Count获取。This method is an O(n) operation, where n is obtained from the ICollection.Count.

适用于

另请参阅