更新时间:2023-02-11 13:23:18
简单的答案是不 - 没有C#等价的C ++位字段。
但是你可能想看看这个: http:// *** .com / questions / 14464 / bit-fields-in-c-sharp [ ^ ]它提供了一个可能有帮助的辅助类,只需要一些工作。
在 Stack Overflow
一些想法:C#中的位字段 [ ^ ]。
Does C# support struct bit definitions?. For example is there a way to
declare a structure like this in c#.
typedef struct
{
UINT16 SrcPort;
UINT16 DstPort;
UINT32 SeqNum;
UINT32 AckNum;
UINT16 Reserved1:4;
UINT16 HdrLength:4;
UINT16 Fin:1;
UINT16 Syn:1;
UINT16 Rst:1;
UINT16 Psh:1;
UINT16 Ack:1;
UINT16 Urg:1;
UINT16 Reserved2:2;
UINT16 Window;
UINT16 Checksum;
UINT16 UrgPtr;
} DIVERT_TCPHDR
Please help me to set bit positions in c# structure. It is very urgent.
The simple answer is "no" - there is no C# equivalent of C++ bit fields.
However you might want to have a look at this: http://***.com/questions/14464/bit-fields-in-c-sharp[^] which does provide a helper class that might assist, with a bit of work.
At Stack Overflow
some ideas: "Bit fields in C#"[^].