c# 合并byte数组

时间:2022-09-03 21:43:18

byte[] defArr = File.ReadAllBytes(filePath);

byte[] md5Arr = GetMd5Hash(filePath);
            
int len = defArr.Length + md5Arr.Length;
byte[] lenArr = BitConverter.GetBytes(len);
if (BitConverter.IsLittleEndian)
   Array.Reverse(lenArr);

//resArr为合并后数组
byte[] resArr = new byte[lenArr.Length + defArr.Length + md5Arr.Length];
lenArr.CopyTo(resArr, 0);
md5Arr.CopyTo(resArr, lenArr.Length);
defArr.CopyTo(resArr, lenArr.Length + md5Arr.Length);