Rupert

::Me(C#,VC,MonoTouch,MonoforAndroid);

导航

数组byte[]合并与讨论

Posted on 2013-02-01 17:04  ArRan  阅读(279)  评论(0编辑  收藏  举报

.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();
.}

 

听说这个更高效:http://stackoverflow.com/questions/415291/best-way-to-combine-two-or-more-byte-arrays-in-c-sharp