Collection<T>.CopyTo(T[], Int32) 方法

定义

从目标数组的指定索引处开始将整个 Collection<T> 复制到兼容的一维 ArrayCopies the entire Collection<T> to a compatible one-dimensional Array, starting at the specified index of the target array.

public:
 virtual void CopyTo(cli::array <T> ^ array, int index);
public void CopyTo (T[] array, int index);
abstract member CopyTo : 'T[] * int -> unit
override this.CopyTo : 'T[] * int -> unit
Public Sub CopyTo (array As T(), index As Integer)

参数

array
T[]

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

index
Int32

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

实现

异常

arraynullarray is null.

index 小于零。index is less than zero.

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

注解

此方法使用 Array.Copy 复制元素。This method uses Array.Copy to copy the elements.

元素按枚举器循环访问 Collection<T>的相同顺序复制到 ArrayThe elements are copied to the Array in the same order in which the enumerator iterates through the Collection<T>.

此方法是一个 O (n)操作,其中 nCount的。This method is an O(n) operation, where n is Count.

适用于