I know how to do this the long way: by creating a byte array of the necessary size and using a for-loop to cast every element from the int array.
I was wondering if there was a faster way, as it seems that the method above would break if the int
was bigger than an sbyte
.
Best Answer
If you want a bitwise copy, i.e. get 4 bytes out of one int, then use
Buffer.BlockCopy
:Don't use
Array.Copy
, because it will try to convert and not just copy. See the remarks on the MSDN page for more info.