Copies a specified number of bytes from a source array starting at a particular offset to a destination array starting at a particular offset.
Assembly: mscorlib (in mscorlib.dll)
static member BlockCopy : src:Array * srcOffset:int * dst:Array * dstOffset:int * count:int -> unit
src or dst is a null reference (Nothing in Visual Basic).
src or dst is not an array of primitives.
The number of bytes in src is less than srcOffset plus count.
The number of bytes in dst is less than dstOffset plus count.
srcOffset, dstOffset, or count is less than 0.
This method copies count bytes from src, beginning at srcOffset, to dst, beginning at dstOffset. Both srcOffset and dstOffset are zero-based; that is, the first byte in each buffer is at position 0, not position 1.
The method accesses the bytes in the src parameter array using offsets into memory, not programming constructs such as indexes or upper and lower array bounds. For example, if in the programming language of your application you declare an Int32 array with a zero-based lower bound of -50, and then pass the array and an offset of 5 to the method, the first array element the method will access is the second element of the array, which is at index -49. Furthermore, which byte of array element -49 is accessed first depends on the endianness of the computer that is executing your application.
As its name suggests, the method copies a block of bytes as a whole, rather than copying one byte at a time. Therefore, if src and dst reference the same array, and the range from srcOffset + count -1 overlaps the range from dstOffset + count - 1, the values of the overlapping bytes are not overwritten before they are copied to the destination. In the following example, the values of bytes 0-16 in an array named arr are copied to bytes 12-28. Despite the overlapping range, the values of the source bytes are successfully copied.
In the following example, the values of bytes 12-28 in an array named arr are copied to bytes 0-16. Again, despite the overlapping range, the values of the source bytes are successfully copied.
The following example copies regions of arrays by using the method. For each operation, it lists the source and destination arrays as both an array of values and as a sequence of bytes. The example illustrates the importance of considering a system's endianness when working with the method: Because Windows systems are little-endian, the lower-order bytes of a primitive data type's value precede the higher-order bytes.
.NET FrameworkSupported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1
.NET Framework Client ProfileSupported in: 4, 3.5 SP1
XNA FrameworkSupported in: 3.0, 2.0, 1.0
Portable Class LibrarySupported in: Portable Class Library
Supported in: Windows Phone 8.1
Supported in: Windows Phone Silverlight 8.1
Supported in: Windows Phone Silverlight 8