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


從目標陣列的指定索引開始,將整個 NameObjectCollectionBase 複製到相容的一維 ArrayCopies the entire NameObjectCollectionBase 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);
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,是從 NameObjectCollectionBase 複製過來之項目的目的端。The one-dimensional Array that is the destination of the elements copied from NameObjectCollectionBase. Array 必須有以零為起始的索引。The Array must have zero-based indexing.


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- 來源 NameObjectCollectionBase 中的項目數大於 index 到目的 array 結尾的可用空間。The number of elements in the source NameObjectCollectionBase is greater than the available space from index to the end of the destination array.

來源 NameObjectCollectionBase 的類型無法自動轉換成目的 array 的類型。The type of the source NameObjectCollectionBase 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.

雖然 ICollection.CopyTo com 用戶端預設看不到此方法,但繼承 NameObjectCollectionBase 類別可以公開該方法,而且可能會在 com 用戶端中造成不必要的行為。While the ICollection.CopyTo method is not visible to COM clients by default, inheriting the NameObjectCollectionBase class can expose it and can cause undesirable behavior in COM clients.

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