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!
评论