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。