请高手给个代码看下
解决方案 »
- 统计某个字母的出现次数
- 【求助】关于文件压缩和磁盘剩余空间预判,就这么点分了,谢谢
- SUSE linux环境下使用mono进行C#开发
- 捕捉类型转换异常
- javascript中checkbox的问题,如何选中下级
- 只学c# 语言, WinForm控件, ado.net,水晶报表,能找到工作吗?
- 刚开始用vs 2003来设计报表,该怎么开始学习?
- 求C#2005+SQLserver2005开发简单信息系统的实例
- C#的有源代码的程序问题??谢谢!--急
- out参数问题 :控制当前方法离开之前 必须对输出参数"scnd"赋值。
- 帅哥美女看过来!Button_Click事件中启动线程有问题!
- 坐标变换函数
struct mystruct
{
public int a;
}
===============System.Runtime.Serialization.Formatters.Binary.BinaryFormatter bf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
System.IO.MemoryStream mem = new System.IO.MemoryStream();
mystruct ms = new mystruct();
ms.a = 100;
bf.Serialize( mem , ms );
mem.Seek( 0 , System.IO.SeekOrigin.Begin );
byte[] b = new byte[ mem.Length ];
mem.Read( b , 0 , b.Length );
struct MsgStruct
{
public int type, session, dataLength;
public char[] data;
public EndPoint clientIPPort;
}
private byte[] Struct2Byte(MsgStruct msg)
{ byte[] bufferData = new byte[12 + msg.dataLength * 2]; byte[] midByte1 = new byte[4]; byte[] midByte2 = new byte[4];
byte[] midByte3 = new byte[4];
byte[] midByte4 = new byte[2]; midByte1 = BitConverter.GetBytes(msg.type);
midByte2 = BitConverter.GetBytes(msg.session);
midByte3 = BitConverter.GetBytes(msg.dataLength); for (int i = 0; i < 4; i++)
{
bufferData[i] = midByte1[i];
bufferData[i + 4] = midByte2[i];
bufferData[i + 8] = midByte3[i];
}
for (int i = 0; i < msg.dataLength; i++)
{
midByte4 = BitConverter.GetBytes(msg.data[i]);
for (int j = 0; j < 2; j++)
bufferData[j + i * 2 + 12] = midByte4[j];
}
return bufferData;
}