读书人

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

发布时间: 2012-08-15 16:57:17 作者: rapoo

请问有没有快速高效的合并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();
[解决办法]
你觉得你的很差,其实一点也不差,在怎折腾也是拷贝过去

读书人网 >C#

热点推荐