0

I'm building up a composite of a number of byte arrays. I'd like to do this quickly but looking for a smart way of doing this:

uint A = 1000;
uint B = 2000;

Key[0:3] = BitConverter.GetBytes(A);
Key[4:7] = BitConverter.GetBytes(B);

I cannot see an easy way to do this. I do not want to use LINQ. Where BitConverter.GetBytes(A) returns 4 bytes. Of course I can do 16 assignments but this is messy. Is there any good looking syntax that is fast?

InitLipton
  • 2,395
  • 5
  • 30
  • 47
disruptive
  • 5,687
  • 15
  • 71
  • 135
  • That's not the exact duplicate. This one possibly asks for list(array) manipulation in range-based manner, and not just about how to copy array parts. – Eugene Podskal Jun 27 '14 at 16:04

1 Answers1

1

Use the Array.Copy method for each of the GetBytes() result.

http://msdn.microsoft.com/en-us/library/system.array.copy(v=vs.110).aspx

Tomas Grosup
  • 6,396
  • 3
  • 30
  • 44