1、 将基础类型转为byte数组存储 1 private byte[] CreateNetDataByteStream(ushort system, ushort host, ushort type, byte[] tx_buf, ushort msg_len, ushort f ...
1、 将基础类型转为byte数组存储
1 private byte[] CreateNetDataByteStream(ushort system, ushort host, ushort type, byte[] tx_buf, ushort msg_len, ushort flag) 2 3 { 4 5 if (tx_buf == null) 6 7 { 8 9 return null;10 11 }12 13 try14 15 {16 17 byte[] data = new byte[msg_len + NetDataHeadLen];18 19 byte[] u16byte = new byte[2];20 21 u16byte = BitConverter.GetBytes(type);22 23 Array.Copy(u16byte, 0, data, 0, 2);24 25 u16byte = BitConverter.GetBytes(flag);26 27 Array.Copy(u16byte, 0, data, 4, 2);28 29 u16byte = BitConverter.GetBytes(msg_len);30 31 Array.Copy(u16byte, 0, data, 2, 2);32 33 // u16byte = BitConverter.GetBytes(CommonConstant.MySystemID);34 35 Array.Copy(u16byte, 0, data, 6, 2);36 37 // u16byte = BitConverter.GetBytes((ushort)CommonConstant.MySeatName);38 39 Array.Copy(u16byte, 0, data, 8, 2);40 41 u16byte = BitConverter.GetBytes(system);42 43 Array.Copy(u16byte, 0, data, 15, 2);44 45 u16byte = BitConverter.GetBytes(host);46 47 Array.Copy(u16byte, 0, data, 17, 2);48 49 tx_buf.CopyTo(data, NetDataHeadLen);50 51 return data;52 53 }54 55 catch56 57 {58 return null;59 60 }61 62 }
原标题:C# 将结构体转为字节流的方式
关键词:C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。