[问题]C# 结构体对齐:如何将变长byte数组对齐

时间:2014-12-19 11:36:39   收藏:0   阅读:185
[StructLayout(LayoutKind.Sequential,Pack=1)] 
struct Report_Read_Parameter 
{ 
    byte Confirmation; 
    byte ListID; 
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] 
    byte[] ParameterID; 
    byte Length; 
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = ***)] // based on the Length 
    byte[] ParameterValue; 
    byte Status; 
}

问题来了,怎么根据字段里的Length来确定byte数组ParameterValue 的长度?

如何实现动态对齐?

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!