You need to copy the Data2 array to the beginning of the Data array without losing the initial data in Data. I try this code:

byte[] Data //Первый массив byte[] Data2 //Первый массив Array.Resize(ref Data, Data.Length + Data2.Length); Array.Copy(Data2, 0, Data, 0, Data2.Length); 

But at the output I get data from Data2 and zeros, all the bytes from Data did not "move" forward, but disappeared.

  • And you copy where? To the begining? And in the beginning you have what? Other people's data? Here and fray. - nick_n_a
  • From the question it is not clear what you want to see in the "head", that in the "tail". You need to either Copy - move the data to the "tail" of Data, or write Data2 not to 0, but to Data.Length which is before changing the length of the array (or it is after resize is Data2.Length - Data.length instead of 0) - nick_n_a

1 answer 1

You will not lose anything if, instead of expanding the array, you simply create a new one, so I recommend using the Linq Concat operation:

 Data = Data2.Concat(Data).ToArray(); 

In fact, Array.Resize does the same thing - it creates a new array and copies elements from the old one into it, after which the old one is simply picked up by the garbage collector.