Array.ConstrainedCopy(Array, Int32, Array, Int32, Int32) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
public:
static void ConstrainedCopy(Array ^ sourceArray, int sourceIndex, Array ^ destinationArray, int destinationIndex, int length);
public static void ConstrainedCopy (Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length);
static member ConstrainedCopy : Array * int * Array * int * int -> unit
Public Shared Sub ConstrainedCopy (sourceArray As Array, sourceIndex As Integer, destinationArray As Array, destinationIndex As Integer, length As Integer)
參數
- sourceIndex
- Int32
32 位元的整數,代表 sourceArray 中的索引,由此開始複製。
- destinationIndex
- Int32
32 位元的整數,代表 destinationArray 中的索引,由此開始儲存。
- length
- Int32
32 位元整數,表示要複製的項目數目。
例外狀況
sourceArray 和 destinationArray 的順位不同。
sourceArray 類型不同於、也非衍生自 destinationArray 類型。
sourceArray 至少有一個項目無法轉換成 destinationArray 的類型。
sourceIndex 小於 sourceArray 的第一個維度下限。
-或-
destinationIndex 小於 destinationArray 的第一個維度下限。
-或-
length 小於零。
length 大於從 sourceIndex 到 sourceArray 結尾的項目數。
-或-
length 大於從 destinationIndex 到 destinationArray 結尾的項目數。
備註
sourceArray和 destinationArray 參數必須具有相同的維度數目。 此 sourceArray 類型必須與 或 衍生自 destinationArray 類型相同, ArrayTypeMismatchException 否則會擲回 。 不同于 Copy , ConstrainedCopy 請先驗證陣列類型的相容性,再執行任何作業。
在多維度陣列之間複製時,陣列的行為就像長一維陣列,其中資料列 (或資料行) 在概念上配置端對端。 例如,如果陣列有三個數據列 (或資料行) 各有四個元素,則從陣列開頭複製六個元素,則會複製第一列 (或資料行) 的所有四個元素,以及第二列 (或資料行) 的前兩個元素。 若要從第三列 (或資料行) 的第二個元素開始複製, sourceIndex 必須是第一列 (或資料行) 加上第二列 (或資料行) 加上兩個數據列的長度上限。
如果 sourceArray 和 destinationArray 重迭,這個方法的行為就如同 在覆寫之前 destinationArray ,在暫存位置中保留的原始值 sourceArray 一樣。
[C++]
這個方法相當於標準 C/C++ 函式 memmove ,而不是 memcpy 。
陣列可以是參考型別陣列或實值型別陣列。 如果 sourceArray 和 destinationArray 都是參考型別陣列,或是 兩種型 Object 別的陣列,則會執行淺層複製。 的 Array 淺層複本是新的 Array ,其中包含與原始 Array 相同的專案參考。 不會複製專案本身或專案所參考的任何專案。 相反地,的深層複本 Array 會複製元素,以及專案直接或間接參考的所有專案。
如果此方法在複製時擲回例外狀況,則 destinationArray 維持不變;因此, ConstrainedCopy 可以在限制的執列區域內使用 (Cer) 。
這個方法是 O (n) 作業,其中 n 是 length 。