比如我有两段byte[] a,b
a有80个byte
b有100个byte
如何将a的80个字节插入b的最前面,使得b成为180个自己的byte[]

解决方案 »

  1.   

    byte[] a = new byte[] { 1, 2, 3 };
                byte[] b = new byte[] { 4, 5, 6, 7 };
                byte[] c = new byte[a.Length+b.Length];            Array.Copy(a, 0, c, 0, a.Length);
                Array.Copy(b, 0, c, a.Length, b.Length);   
      

  2.   

    新建一个byte数组作为中间变量
      

  3.   

     public string test() 
            {
                byte[] a = new byte[] { 1, 2, 3 };
                byte[] b = new byte[] { 4, 5, 6, 7 };
                byte[] c = new byte[a.Length + b.Length];
                Array.Copy(a, 0, c, 0, a.Length);
                Array.Copy(b, 0, c, a.Length, b.Length);
                string te;
                StringBuilder sb = new StringBuilder(); ;
                for (int i = 0; i < c.Length; i++)
                {
                    sb.Append(c[i]);
                }
                string te;
                te = sb.ToString();
                return te;
            }
      

  4.   

                    byte[] a = new byte[80];
                    byte[] b = new byte[100];
                    byte[] c = new byte[a.Length + b.Length];
                    Buffer.BlockCopy(a, 0, c, 0, a.Length);
                    Buffer.BlockCopy(b, 0, c, a.Length, c.Length);
                    b = c;
      

  5.   

    找一个中间变量  因为在C# 中 这个byte[] 长度是固定的