C#byte数组合并

byte[] head = new byte[] { 0x7e }; byte[] type = new byte[] { 0x00 }; byte[] content = Encoding.Default.GetBytes("ABCDEGF"); byte[] last = new byte[] { 0x23 }; byte[] full=new byte[head.Length+type.Length+content.Length+last.Length]; //head.CopyTo(full,0); //type.CopyTo(full, head.Length); //content.CopyTo(full,head.Length+type.Length); //last.CopyTo(full, head.Length + type.Length + content.Length); Stream s = new MemoryStream(); s.Write(head, 0, 1); s.Write(type,0,1); s.Write(content,0,content.Length); s.Write(last, 0, 1); s.Position = 0; int r = s.Read(full, 0, full.Length); if (r>0) { Console.WriteLine(Encoding.Default.GetString(full)); Console.WriteLine(full.Length); Console.WriteLine(full[0].ToString()); Console.WriteLine(full[1].ToString()); Console.WriteLine(full[9].ToString()); Console.Read(); }

你可能感兴趣的:(Stream,byte)