Array.ConstrainedCopy Method
Microsoft Silverlight will reach end of support after October 2021. Learn more.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Syntax
'Declaration
<SecuritySafeCriticalAttribute> _
Public Shared Sub ConstrainedCopy ( _
sourceArray As Array, _
sourceIndex As Integer, _
destinationArray As Array, _
destinationIndex As Integer, _
length As Integer _
)
[SecuritySafeCriticalAttribute]
public static void ConstrainedCopy(
Array sourceArray,
int sourceIndex,
Array destinationArray,
int destinationIndex,
int length
)
Parameters
- sourceArray
Type: System.Array
The Array that contains the data to copy.
- sourceIndex
Type: System.Int32
A 32-bit integer that represents the index in the sourceArray at which copying begins.
- destinationArray
Type: System.Array
The Array that receives the data.
- destinationIndex
Type: System.Int32
A 32-bit integer that represents the index in the destinationArray at which storing begins.
- length
Type: System.Int32
A 32-bit integer that represents the number of elements to copy.
Exceptions
Exception | Condition |
---|---|
ArgumentNullException | sourceArray is nulla null reference (Nothing in Visual Basic). -or- destinationArray is nulla null reference (Nothing in Visual Basic). |
RankException | sourceArray and destinationArray have different ranks. |
ArrayTypeMismatchException | The sourceArray type is neither the same as nor derived from the destinationArray type. |
InvalidCastException | At least one element in sourceArray cannot be cast to the type of destinationArray. |
ArgumentOutOfRangeException | sourceIndex is less than the lower bound of the first dimension of sourceArray. -or- destinationIndex is less than the lower bound of the first dimension of destinationArray. -or- length is less than zero. |
ArgumentException | length is greater than the number of elements from sourceIndex to the end of sourceArray. -or- length is greater than the number of elements from destinationIndex to the end of destinationArray. |
Remarks
The sourceArray and destinationArray parameters must have the same number of dimensions. The sourceArray type must be the same as or derived from the destinationArray type; otherwise, an ArrayTypeMismatchException is thrown.
When copying between multidimensional arrays, the array behaves like a long one-dimensional array, where the rows (or columns) are conceptually laid end-to-end. For example, if an array has three rows (or columns) with four elements each, copying six elements from the beginning of the array would copy all four elements of the first row (or column) and the first two elements of the second row (or column). To start copying from the second element of the third row (or column), sourceIndex must be the upper bound of the first row (or column) plus the length of the second row (or column) plus two.
If sourceArray and destinationArray overlap, this method behaves as if the original values of sourceArray were preserved in a temporary location before destinationArray is overwritten.
[C++]
This method is equivalent to the standard C/C++ function memmove, not memcpy.
The arrays can be reference-type arrays or value-type arrays. If sourceArray and destinationArray are both reference-type arrays or are both arrays of type Object, a shallow copy is performed. A shallow copy of an Array is a new Array containing references to the same elements as the original Array. The elements themselves or anything referenced by the elements are not copied. In contrast, a deep copy of an Array copies the elements and everything directly or indirectly referenced by the elements.
This method is an O(n) operation, where n is length.
Version Information
Silverlight
Supported in: 5, 4
Platforms
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.