永发信息网

C#使用位域有什么好的解决方法

答案:2  悬赏:0  手机版
解决时间 2021-01-27 23:14
  • 提问者网友:我没有何以琛的痴心不悔
  • 2021-01-27 07:45
C#使用位域有什么好的解决方法
最佳答案
  • 五星知识达人网友:笑迎怀羞
  • 2021-01-27 08:12
C# 虽说是不能直接指定位域。但是,你可以通过使用相应长度的类型以及通过 UnmanagedType 来指定要使用的长度嘛。

[StructLayout(LayoutType.Explicit)]
struct FileHead
{
[Offset(0)]
[MarshalAs(UnmanagedType.U2)]
public UInt32 Year;
[Offset(16)]
[MarshalAs(UnmanagedType.U1)]
public UInt32 Day;
[Offset(24)]
[MarshalAs(UnmanagedType.U1)]
public UInt32 Month;
[Offset(32)]
[MarshalAs(UnmanagedType.U2)]
public UInt32 Hour;
[Offset(40)]
[MarshalAs(UnmanagedType.U1)]
public UIn32 Minute;
[Offset(48)]
[MarshalAs(UnmanagedType.U1)]
public UInt32 Second;
}
全部回答
  • 1楼网友:动情书生
  • 2021-01-27 08:42
可以私聊我~
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯