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

定義

從特定的 Collection 索引開始,將 Array 的項目複製到 ArrayCopies 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,是從 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

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.

備註

元素會以列舉值逐一查看 Collection 物件的相同順序複製到 ArrayThe elements are copied to the Array in the same order in which the enumerator iterates through the Collection object.

這個方法是 O (n)運算,其中 n 是從 ICollection.Count取得。This method is an O(n) operation, where n is obtained from the ICollection.Count.

適用於

另請參閱