C# byte 数组合并

01.byte[] head = new byte[] { 0x7e };
02.byte[] type = new byte[] { 0x00 };
03.byte[] content = Encoding.Default.GetBytes("ABCDEGF");
04.byte[] last = new byte[] { 0x23 };
05.byte[] full=new byte[head.Length+type.Length+content.Length+last.Length];
06.//head.CopyTo(full,0);
07.//type.CopyTo(full, head.Length);
08.//content.CopyTo(full,head.Length+type.Length);
09.//last.CopyTo(full, head.Length + type.Length + content.Length);
10.Stream s = new MemoryStream();
11.s.Write(head, 0, 1);
12.s.Write(type,0,1);
13.s.Write(content,0,content.Length);
14.s.Write(last, 0, 1);
15.s.Position = 0;
16.int r = s.Read(full, 0, full.Length);
17.if (r>0)
18.{
19. Console.WriteLine(Encoding.Default.GetString(full));
20. Console.WriteLine(full.Length);
21. Console.WriteLine(full[0].ToString());
22. Console.WriteLine(full[1].ToString());
23. Console.WriteLine(full[9].ToString());
24. Console.Read();
25.}
posted @ 2011-03-15 10:23  许明吉博客  阅读(21957)  评论(1编辑  收藏  举报