arraysvb.netbitconverter

Filling byte array from Int16 values


I'm trying to use BitConverter.GetBytes to transfer 16 bit values into a byte array using VB.net. The simple readBuffer(z) = BitConverter.GetBytes(p) is rejected by vb.net. What is going wrong?

Thanks for any advice!

readBuffer(z) = BitConverter.GetBytes(p)

fails to compile

readBuffer() is a Byte array and p is a Int16 variable.


Solution

  • GetBytes method returns an array that needs to be copied to a specific position in your array:

    BitConverter.GetBytes(p).CopyTo(readBuffer, z)