解决方案 »
- int.parse方法具体是怎么实现的?
- 马上10.1了,都来秀秀自己的实用代码,顺便散分
- c# StringBuilder 效率实战(说不定对你有帮助哦)
- 如何才能避免类中引用类型的只读属性,该类型的属性不被修改
- 关于双色球选注的问题
- Clickonce更新安装时,有没有办法可以让用户自定义安装路径啊?
- 违反并发性: DeleteCommand 影响了预期 1 条记录中的 0 条?
- Datagrid使用中问题
- 用正则表达式检测格式的问题
- 深圳的朋友进来,再送100分............
- 跟visio似的 拖动按钮生成又可在Panel上移动的东西 都是什么控件?
- 请教 在Asp.Net下 的方法?
u16 ushort
u32 uint
public class WAVEFORMATEX
{
public byte ver = 0;public UInt16 len = 0;public UInt32 crc = 0;public byte[] third_id = new byte[64];public IntPtr url_data = IntPtr.Zero;
}
[StructLayoutAttribute(LayoutKind.Sequential,Pack = 1)]
public struct MSG_HEAD_ST
{
[MarshalAs(UnmanagedType.I1, SizeConst = 1)]
private byte ver; public byte Ver
{
get { return ver; }
set { ver = value; }
}
[MarshalAs(UnmanagedType.I2, SizeConst = 2)]
private short len; public short Len
{
get { return len; }
set { len = value; }
}
[MarshalAs(UnmanagedType.I4, SizeConst = 4)]
private int crc; public int Crc
{
get { return crc; }
set { crc = value; }
}
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
private byte[] third_id; public byte[] Third_id
{
get { return third_id; }
set { third_id = value; }
}
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
private string url_data; public string Url_data
{
get { return url_data; }
set { url_data = value; }
}
}
我是这样写的 这样写 计算出的字节数多了一个 Url_data就是这个 他本身是0字节的 怎么才能把它定义成0字节的呢
public partial class Form1 : Form
{
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public class MSG_HEAD_ST
{
public byte ver = 0; public UInt16 len = 0; public UInt32 crc = 0; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 64)]
public byte[] third_id = new byte[64]; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)]
public string Url_data = null;
} public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
Console.WriteLine(Marshal.SizeOf(typeof(MSG_HEAD_ST)));
MSG_HEAD_ST o = new MSG_HEAD_ST();
o.Url_data = "12345";
Console.WriteLine(o.Url_data);
}
}