Terry
Terry

Reputation: 3

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.

Upvotes: 0

Views: 46

Answers (1)

Konstantin Makarov
Konstantin Makarov

Reputation: 1376

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

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

Upvotes: 1

Related Questions