1

First, I am very new to c#, so please, bear with me. I am trying to set 3 ints and 4 bytes to a computer via UDP. I've used this thread to help with concatenating my variables Best way to combine two or more byte arrays in C#. Currently, I am having an error trying to BlockCopy the bytes into an array. My array is 12 bytes long and I need bytes 9, 4, 5 and 6. My code is

byte[] UDPPacket = new byte[16];
Buffer.BlockCopy(button[9],0,UDPPacket,0,1);

and it is erroring with

(parameter)byte[]buttons

I believe the BlockCopy method works for a bytewise copy of one array to the other. Any insight into what I'm doing wrong?

Community
  • 1
  • 1

1 Answers1

1

The expression button[9] is not an array, it's a single byte.

Use the index as offset instead:

Buffer.BlockCopy(button,9,UDPPacket,0,1);
Guffa
  • 687,336
  • 108
  • 737
  • 1,005