C# byte 数组合并(转载)
转载自 http://www.cnblogs.com/jxsoft/archive/2011/03/15/1984535.html
01.byte[] head =newbyte[] { 0x7e };
02.byte[] type =newbyte[] { 0x00 };
03.byte[] content = Encoding.Default.GetBytes("ABCDEGF");
04.byte[] last =newbyte[] { 0x23 };
05.byte[] full=newbyte[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.}
02.byte[] type =newbyte[] { 0x00 };
03.byte[] content = Encoding.Default.GetBytes("ABCDEGF");
04.byte[] last =newbyte[] { 0x23 };
05.byte[] full=newbyte[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.}