日期:2014-05-18  浏览次数:20786 次

请问有没有快速高效的合并byte[]的方法?

我现在是这么合并的 ,感觉很差
C# code

     byte[] a ;
            byte[] b ;
            byte[] c = new byte[] { Convert.ToByte(a.Length + b.Length) };

            byte[] d = new byte[c.Length + a.Length + b.Length];
            int pos = 0;
            Buffer.BlockCopy(c, 0, d, 0, c.Length);
            pos += c.Length;
            Buffer.BlockCopy(a, 0, d, pos, a.Length);
            pos += a.Length;

            Buffer.BlockCopy(b, 0, d, pos, b.Length);




------解决方案--------------------
C# code
 byte[] a={1,2,3};
                byte[] b={5,6,7,8};
                byte[] c = new byte[] { Convert.ToByte(a.Length + b.Length) };

                byte[] d = a.Concat(b).Concat(c).ToArray();

------解决方案--------------------
byte[] a = { 1, 2, 3 };
byte[] b = { 5, 6, 7, 8 };
List<byte> c = new List<byte>(a);
c.AddRange(b);
return c.ToArray();
------解决方案--------------------
你觉得你的很差,其实一点也不差,在怎折腾也是拷贝过去