VB.net与C#整数位域读写示例代码

VB.netC#开发中,整数位域可以高效地处理位级数据。以下是VB.net和C#示例代码,展示如何进行整数位域的设置和读取:

VB.net示例:

Public Class BitFieldExample
    Public Structure BitField
         Public Bit1 As Boolean
         Public Bit2 As Boolean
         Public Bit3 As Boolean
    End Structure
End Class

C#示例:

public struct BitField
{
    [System.Runtime.InteropServices.FieldOffset(0)] public bool Bit1;
    [System.Runtime.InteropServices.FieldOffset(1)] public bool Bit2;
    [System.Runtime.InteropServices.FieldOffset(2)] public bool Bit3;
}
vb 文件大小:4.66KB