请问怎样将结构体转化为二进制数组 请问怎样将结构体转化为二进制数,这个结构体包括String和int型数据 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public class MsgHead { private int _MsgLength ; private int _CmdID; private ErrorLog _log = new ErrorLog(); public MsgHead(int MsgLength,int CmdID) { try { this._MsgLength = MsgLength ; this._CmdID = CmdID; } catch(Exception e) { this._log.EnrolLog(e); } } /// <summary> /// 将数据打包成二进制流 /// </summary> /// <returns></returns> public byte [] GetBytes() { try { byte [] data = new byte[8]; int place = 0; Buffer.BlockCopy(BitConverter.GetBytes(_MsgLength),0,data,place,4); place += 4; Buffer.BlockCopy(BitConverter.GetBytes(_CmdID),0,data,place,4); return data; } catch(Exception e) { this._log.EnrolLog(e); return new byte[0]; } }这是我现成的代码你整理一下吧! froeach的问题 大家可以帮我吗?我是新手!`` 请问windows窗体的MD5加密怎么做?急急急 如何打开在别的机子上的asp.net项目 Web应用程序中,如何实现动态加载DLL? 郁闷!系统公告太多了,导致我的短信息看不见 怎样在现有DataSet数据集中提取,指定范围的数据? c#怎么用hook判断失去打开一个word文档的焦点? 帮忙把一个php代码翻译成C#吧。版主求助 如何得到Internet上的标准时间,然后和本地机器同步一下? 从SQLSERVER数据库中读数据出来是怎么做的呢?谢谢 100分求 C#.net 里面使用 FreeTextBox 的例子给相关提示也行
{
private int _MsgLength ;
private int _CmdID; private ErrorLog _log = new ErrorLog(); public MsgHead(int MsgLength,int CmdID)
{
try
{
this._MsgLength = MsgLength ;
this._CmdID = CmdID;
}
catch(Exception e)
{
this._log.EnrolLog(e);
}
} /// <summary>
/// 将数据打包成二进制流
/// </summary>
/// <returns></returns>
public byte [] GetBytes()
{
try
{
byte [] data = new byte[8]; int place = 0;
Buffer.BlockCopy(BitConverter.GetBytes(_MsgLength),0,data,place,4);
place += 4;
Buffer.BlockCopy(BitConverter.GetBytes(_CmdID),0,data,place,4); return data;
}
catch(Exception e)
{
this._log.EnrolLog(e);
return new byte[0];
}
}这是我现成的代码
你整理一下吧!