byte[] byteMsg1 = new byte[] { 0x1C, 0x21, 0x0C, 0x1B, 0x21, 0x30 };
string strMsg2 = "ABCDE";
byte[] byteMsg3 = new byte[] { 0x01, 0x02, 0x03, 0x04 };
string strMsg4 = "FGHI";以上这些字符串用什么方法连接在一个byte[]里面?

解决方案 »

  1.   

    先把string变成char[]然后在把char[]转换成byte
      

  2.   

       using System.Text; 
    byte[] b= Encoding.UTF8.GetBytes("sss");
           b.CopyTo();具体代码不写了,无非是一个知识点,你知道了,自己就能写出来
      

  3.   


        byte[] byteMsg1 = new byte[] { 0x1C, 0x21, 0x0C, 0x1B, 0x21, 0x30 };
                string strMsg2 = "ABCDE";
                byte[] byteMsg3 = new byte[] { 0x01, 0x02, 0x03, 0x04 };
                string strMsg4 = "FGHI";             System.IO.MemoryStream _Memory = new System.IO.MemoryStream();            _Memory.Write(byteMsg1, 0, byteMsg1.Length);            byte[] _StrByte =System.Text.Encoding.ASCII.GetBytes(strMsg2);
                _Memory.Write(_StrByte, 0, _StrByte.Length);            _Memory.Write(byteMsg3, 0, byteMsg3.Length);            _StrByte = System.Text.Encoding.ASCII.GetBytes(strMsg4);
                _Memory.Write(_StrByte, 0, _StrByte.Length);
                byte[] _AddByte =new byte[_Memory.Length];            _Memory.Position=0;
                _Memory.Read(_AddByte,0,_AddByte.Length);
    合并到一起...但感觉这样没意义啊