C#是否支持结构位定义 [英] Does C# support struct bit definitions

查看:172
本文介绍了C#是否支持结构位定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C#是否支持struct bit definitions?例如,是否有一种方法可以在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确认: 1 ;
UINT16 Urg: 1 ;
UINT16 Reserved2: 2 ;
UINT16窗口;
UINT16校验和;
UINT16 UrgPtr;
} DIVERT_TCPHDR





请帮我设置c#结构中的位位置。这是非常紧急的。

解决方案

简单的答案是不 - 没有C#等价的C ++位字段。



但是你可能想看看这个: http:// stackoverflow .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://stackoverflow.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#"[^].


这篇关于C#是否支持结构位定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆