This might be a silly question, but have not found a simple answer yet...
I'm trying to insert a simple c# byte array into another byte array at a specific position. E.g. the existing bytes should be not be overridden, but just moved further back. Really just like you copy page some text block inside an existing text block.
But I would assume this is something common and should be easier? Or am I wrong?
Use a List<byte>
instead of a byte[]
; it will provide the flexibility you are looking for...
List<byte> b1 = new List<byte>() { 45, 46, 47, 50, 51, 52 };
List<byte> b2 = new List<byte> { 48, 49 };
b1.InsertRange(3, b2);
Then if you need to go back to a byte[]
for whatever reason you can call...
b1.ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With