[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 的长度?

如何实现动态对齐?

 

在网上查了一下,但凡是声明为ByValArray类型,就必须要跟上SizeConst,而且设置SizeConst=Length时,编译器会报错

"An object reference is required for the non-static field, method, or property 'NGK.BLL.Commands.Report.Report_Read_Parameter.Length'"

相关文章:

  • 2021-09-08
  • 2021-11-26
  • 2022-12-23
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-31
猜你喜欢
  • 2022-12-23
  • 2021-11-08
  • 2021-04-10
  • 2021-06-07
  • 2021-11-10
  • 2021-10-10
  • 2022-12-23
相关资源
相似解决方案