List<T>.ICollection.CopyTo(Array, Int32) 方法

定义

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

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

参数

array
Array

作为从 Array 复制的元素目标的一维 ICollectionThe one-dimensional Array that is the destination of the elements copied from ICollection. Array 必须具有从零开始的索引。The Array must have zero-based indexing.

arrayIndex
Int32

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

实现

异常

arraynullarray is null.

arrayIndex 小于 0。arrayIndex is less than 0.

array 是多维数组。array is multidimensional.

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

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

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

注解

备注

如果源 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 InvalidCastException, whereas the generic implementations throw ArgumentException.

此方法的运算复杂度为 O (n),其中nCountThis method is an O(n) operation, where n is Count.

适用于