C#不直接支持struct里面的位域,可以用enum+FlagsAttribute来做: [Flags]
public enum ComStatFlags {
fCtsHold = 0x1, fDsrHold = 0x2, fRlsdHold = 0x4,
fXoffHold = 0x8, fXoffSent = 0x10, fEof = 0x20,
fTxim = 0x40
} public strut COMSTAT {
public ComStatFlags flags;
public uint cbInQue;
public uint cbOutQue;
...
}
public enum ComStatFlags {
fCtsHold = 0x1, fDsrHold = 0x2, fRlsdHold = 0x4,
fXoffHold = 0x8, fXoffSent = 0x10, fEof = 0x20,
fTxim = 0x40
} public strut COMSTAT {
public ComStatFlags flags;
public uint cbInQue;
public uint cbOutQue;
...
}
public enum ComStatFlags {
fCtsHold=0,
fDsrHold,
fRlsdHold,
fXoffHold,
fXoffSent,
fEof,
fTxim
}
public strut COMSTAT {
//这一句不是很确定,可能需要构造函数,自己
//这样的初始值是false
public BitArray State=new BitArray(32);
public uint cbInQue;
public uint cbOutQue;
...
}
//使用
COMSTAT test;
test.State[fCtsHold]=true;