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 型別衍生;否則,會拋出 an ArrayTypeMismatchException 。 與 Copy不同, ConstrainedCopy 在執行任何操作前,它會驗證陣列類型的相容性。
在多維陣列間複製時,陣列表現為長的一維陣列,列(或欄位)概念上是端對端排列。 例如,若陣列有三列(或列),每列有四個元素,從陣列起始複製六個元素,將複製第一列(或列)的全部四個元素,以及第二列(或列)的前兩個元素。 要開始從第三列(或列)的第二個元素複製, sourceIndex 必須是第一列(或列)的上界加上第二列(或列)的長度再加二。
若 sourceArray 與 destinationArray 重疊,此方法表現為先前 的 sourceArray 原始值被暫時保留 destinationArray 於被覆寫。
[C++]
此方法等價於標準的 C/C++ 函式 memmove,而非 memcpy。
陣列可以是參考型或值型型陣列。 若 sourceArray 和 destinationArray 都是參考型態陣列,或 都是型別 Object的陣列,則會執行淺層複製。 淺Array層副本 是包含與原始Array相同元素的 新副本Array。 元素本身或元素所參考的任何東西都不會被複製。 相較之下,深層複製品 Array 會複製元素以及元素直接或間接引用的所有事物。
若此方法在複製時拋出例外,則 destinationArray 保持不變;因此可在 ConstrainedCopy 受限執行區域Cer()中使用。
此方法是一個$O(n)$運算,其中$n$為 length。