I m receiving several bit fields from hardware.
My code was originally:
public readonly byte LowByte;
public bool Timer { get { return (LowByte & 1) == 1; } }
然后,我记得国旗,正在考虑将其改为:
[Flags]
public enum LowByteReasonValues : byte
{
Timer = 1,
DistanceTravelledExceeded = 2,
Polled = 4,
GeofenceEvent = 8,
PanicSwitchActivated = 16,
ExternalInputEvent = 32,
JourneyStart = 64,
JourneyStop = 128
}
public readonly LowByteReasonValues LowByte;
public bool Timer { get { return (LowByte & LowByteReasonValues.Timer) == LowByteReasonValues.Timer; } }
等等。
哪些是最佳做法,哪些是每一种做法的利弊?
EDIT:我很想知道两种办法之间是否有任何实际差异,特别是在业绩方面。 我不想征求关于编码风格的意见(除非从微软准则中得出),因为这会使问题变得不建设性。 感谢。