I am trying to copy the value of a uint into a byte array in C#. I have managed to accomplish this using code in an unsafe context but ideally, I would like to do this in a safe context
The code I am currently using is this
var bytes = new byte[] {0x68, 0x00, 0x00, 0x00, 0x00}
fixed (byte* bytesPointer = bytes )
{
*(ulong*)(bytesPointer + 1) = value;
}
The equivalent of what I am trying to accomplish in C# can be done like this in C++
unsigned char bytes[] = {0x68, 0x00, 0x00, 0x00, 0x00}
memcpy(((unsigned long)bytes + 1), value, 4);
How could I do this in a safe context in C#?