第一个byte[] byteOne=new byte[]{12,21,33,44,55,66,87,18,29,0,0,0,0,0};
第二个byte[] byteTwo=new byte[]{10,11,12,13,14};
如何把两个byte合为一个,使之变为byte[] bytes=new byte[]{12,21,33,44,55,66,87,18,29,10,11,12,13,14} 寻求好方法...........
第二个byte[] byteTwo=new byte[]{10,11,12,13,14};
如何把两个byte合为一个,使之变为byte[] bytes=new byte[]{12,21,33,44,55,66,87,18,29,10,11,12,13,14} 寻求好方法...........
byte[] byteTwo = new byte[] { 10, 11, 12, 13, 14 };
byte[] q= byteOne.Concat(byteTwo).ToArray();
byte[] bsInput = Encoding.UTF8.GetBytes("");
int inputBytesCount = bsInput.Length;
byte[] bs1 = new byte[4 + 3];
Buffer.BlockCopy(BitConverter.GetBytes(""), 0, bs1, 0, 4);byte1.CopyTo(newByte, 0);
byte2.CopyTo(newByte, byte1.length)
Array.Copy
byte[] byteTwo = new byte[] { 10, 11, 12, 13, 14}; int start = Array.IndexOf(byteOne, (byte)0);
Array.Copy(byteTwo, 0, byteOne,start , (byteTwo.Length > byteOne.Length - start? byteOne.Length - start: byteTwo.Length) );
int len0 = bufData[0] * 1;
int len1 = bufData[1] * 255;
int len = len0 + len1;
byteGather = new byte[len];
while (len > 0)
{
bufData = new byte[len];
int recIndex = ClientConnService.localSocket.Receive(bufData, len, 0);
len = len - recIndex;
}其中len为接收数据的长度,有的时候数据过大一次不能接收完,要分几次接收,在这里我用了一个while,服务器发送的数据实际长度是50,客户端计算出要接收的数据len=50,而在接收数据时,由于各种原因只能够接收到40位的数据,后面还有10位数据没有接收,那么得到第一个bufData数据的实际长度是40,但是bufData前面已经付给了长度即为len,也就是说bufData后面的10个长度是空的.第二次接收数据的时候len=10,那么接收到的这10位长度数据,我如何添加到bufData的后面10位为空的位置中,如果数据很大while循环可能不止两次,如何解决......
Console.WriteLine(b);
//输出
...
byte[] result = byteList.ToArray();
{
byte[] tempdata = new byte[ pre.Length + data.Length];
Array.Copy(pre, 0, tempdata, 0, pre.Length);
Array.Copy(data, 0, tempdata, pre.Length, data.Length);
return tempdata;
}
byte[] byteOne = new byte[] { 12, 21, 33, 44, 55, 66, 87, 18, 29, 0, 0, 0, 0, 0 };
byte[] byteTwo = new byte[] { 10, 11, 12, 13, 14 };
byte[] q = byteOne.Concat(byteTwo).Where(a=>(int)a>0).ToArray();