I have a byte array, for example:
{0,1,2,3,4,5,6,7,8,9}
I want to insert the smaller array into:
The array which I want to insert after the third index of the original array:
{11,11,11}
So the final array should look like this:
{0,1,2,3,11,11,11,4,5,6,7,8,9}
as you can see I need to keep the original values of the array, shift them left, and put the new array instead of it. I was looking into Array.Copy() But it's overwriting the original values, not shifting them
Array.Copy()to copy first part of array1, then array2, then second part of array1.InsertRange(3, otherData)on aList<byte>would let you concentrate on getting work done rather than fussing around with copying array values around, etc.List<byte>to aFileStreamwithout having to convert to an array usingfileStream.Write(CollectionsMarshal.AsSpan(listOfBytes));(This does not make a copy of the data so it's very efficient, but you mustn't change thelistOfBytesin another thread whilefileStream.Write()is doing its thing.)