在C#中要实现两个byte合并应该怎么实现?
例如: OpenFileDialog ofd = new OpenFileDialog();
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                int retry = 0;
                FileStream myFile = new FileStream(ofd.FileName, FileMode.Open); 
                byte[] bty = new byte[myFile.Length];
                myFile.Read(bty, 0, Convert.ToInt32(myFile.Length));
                myFile.Close();
                
                byte[] localByte = Encoding.UTF8.GetBytes("本地主机的信息".ToCharArray());
                ??????
             }??????那是要实现将localByte和bty合并成一个byte[],应该是如何实现?

解决方案 »

  1.   

    MemoryStream ms=new MemoryStream();
    ms.Write(localByte,0,localByte.Length);
    ms.Write(bty,0,bty.Length);byte [] anotherBytes=ms.GetBuffer();
      

  2.   

     public void MergeBytes(byte[] pByteA, byte[] pByteB)
            {
                int aCount = pByteA.Length;
                int bCount = pByteB.Length;            byte[] c = new byte[aCount+bCount];            for (int i = 0; i < aCount; i++)
                {
                    c[i] = pByteA[i];
                }            for (int i = 0; i < bCount; i++)
                {
                    c[aCount + i] = pByteB[i]; 
                }
            }