語言

SortedDictionary<TKey,TValue>.CopyTo 方法

定義

將 的 SortedDictionary<TKey,TValue> 元素複製到指定的結構陣列 KeyValuePair<TKey,TValue> ,從指定的索引開始。

public:
 virtual void CopyTo(cli::array <System::Collections::Generic::KeyValuePair<TKey, TValue>> ^ array, int index);
public void CopyTo(System.Collections.Generic.KeyValuePair<TKey,TValue>[] array, int index);
abstract member CopyTo : System.Collections.Generic.KeyValuePair<'Key, 'Value>[] * int -> unit
override this.CopyTo : System.Collections.Generic.KeyValuePair<'Key, 'Value>[] * int -> unit
Public Sub CopyTo (array As KeyValuePair(Of TKey, TValue)(), index As Integer)

參數

array
KeyValuePair<TKey,TValue>[]

一維結構陣列 KeyValuePair<TKey,TValue> 作為從當前 SortedDictionary<TKey,TValue> 元素複製的目的地,陣列必須具有以零為基礎的索引。

index
Int32

複製開始的零基索引 array 。

實作

例外狀況

array 是 null。

index 小於0。

來源 SortedDictionary<TKey,TValue> 中的元素數量大於從 index 目的地 array到末端的可用空間。

備註

Note

若來源的類型 SortedDictionary<TKey,TValue> 無法自動轉換為目的 array的類型,則非通用實作 ICollection.CopyTo 的拋出 InvalidCastException,而泛型實作則拋出 ArgumentException。

此方法是一個 O(n) 運算,其中 n 為 Count。

適用於