C# 字节数组(byte[])拼接—笔记

C# 字节数组(byte[])拼接—笔记

猿掌柜
2023-03-31 / 0 评论 / 21 阅读 / 正在检测是否收录...
List<byte> byteSource = new List<byte>();
byteSource.Add(11);
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < RunCount; i++)
   {
      byte[] newData = new byte[10] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
      byteSource.AddRange(newData);
    }
byte[] data = byteSource.ToArray();
byte[] lastData1 = data .Skip(4).ToArray();    // 从第4位起读至最后
byte[] lastData2 = data .Skip(4).Take(3).ToArray();    // 从第4位起读3位
sw.Stop();

方法二

   public static byte[] CombineByte(byte[] a, byte[] b, byte[] c)
        {
            byte[] res = new byte[a.Length + b.Length+c.Length];

            Array.Copy(a, 0, res, 0, a.Length);
            Array.Copy(b, 0, res, a.Length, b.Length);
            Array.Copy(c, 0, res, a.Length+b.Length, c.Length);

            return res;
        }

OK!

1

评论

博主关闭了当前页面的评论