Udostępnij za pośrednictwem


A short note about Buffer.BlockCopy [Gang Peng]

Buffer.BlockCopy has following signature:

public static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count);

 

It copies count bytes from src, beginning at srcOffset, to dst, beginning at dstOffset.

srcOffset is the byte offset into src and dstOffset is the byte offset into dst.

Buffer.BlockCopy only supports array of primitive types to keep type safety (MSDN document is not accurate): Boolean, Char, SByte, Byte, Int16, UInt16, Int32, UInt32, Int64, UInt64, Single, Double.

Internally Buffer.BlockCopy just does a memcpy. The interesting fact about this is you can use Buffer.BlockCopy to copy data between arrays of different primitive types:

https://www.dotnet247.com/247reference/msgs/18/93978.aspx

Comments

  • Anonymous
    December 07, 2004
    Hmmm...looks like this class was before any FxCop standards were in place...
  • Anonymous
    December 07, 2004
    You are talking about the naming. :)