CollectionBase.ICollection.CopyTo(Array, Int32) 方法

定義

從目標陣列的指定索引開始,將整個 CollectionBase 複製到相容的一維 ArrayCopies the entire CollectionBase to a compatible one-dimensional Array, starting at the specified index of the target array.

 virtual void System.Collections.ICollection.CopyTo(Array ^ array, int index) = System::Collections::ICollection::CopyTo;
void ICollection.CopyTo (Array array, int index);
abstract member System.Collections.ICollection.CopyTo : Array * int -> unit
override this.System.Collections.ICollection.CopyTo : Array * int -> unit
Sub CopyTo (array As Array, index As Integer) Implements ICollection.CopyTo

參數

array
Array

一維 Array,是從 CollectionBase 複製過來之項目的目的端。The one-dimensional Array that is the destination of the elements copied from CollectionBase. 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.

array 是多維的。array is multidimensional.

-或--or- 來源 CollectionBase 中的項目數大於 index 到目的 array 結尾的可用空間。The number of elements in the source CollectionBase is greater than the available space from index to the end of the destination array.

來源 CollectionBase 的類型無法自動轉換成目的 array 的類型。The type of the source CollectionBase cannot be cast automatically to the type of the destination array.

備註

指定的陣列必須是相容的類型。The specified array must be of a compatible type.

這個方法會使用 Array.Copy 複製元素。This method uses Array.Copy to copy the elements.

這個方法是一項作業 O(n) ,其中 nCountThis method is an O(n) operation, where n is Count.

適用於