J
Jim H
I have an enum that is derived from byte and a member that is of type byte.
The compiler complains when I try to OR the one of the enum values with the
byte. Why?
[Flags]
public enum eDataPosition : byte
{
ePosition1 = 0x08, //00 001 000
ePosition2 = 0x10, //00 010 000
ePosition3 = 0x18, //00 011 000
ePosition4 = 0x20, //00 100 000
ePosition5 = 0x28, //00 101 000
MASK = 0x38 //00 111 000
};
public byte m_BitMask = 0;
public eDataPosition DataPosition
{
get { return (eDataPosition)(m_PacketMask | eDataPosition.MASK); }
set { m_PacketMask |= value; }
}
I get the following errors:
Operator '|' cannot be applied to operands of type 'byte' and
'TestInterface.Test.eDataPosition'
Cannot implicitly convert type 'TestInterface.Test.eDataPosition' to 'byte'
Operator '|=' cannot be applied to operands of type 'byte' and
'TestInterface.Test.eDataPosition'
I know I can cast them back and forth but why do I have to?
I tried it with and without the "Flags" attribute and with and without the
byte base-type. I get the same errors either way.
Thanks,
jim
The compiler complains when I try to OR the one of the enum values with the
byte. Why?
[Flags]
public enum eDataPosition : byte
{
ePosition1 = 0x08, //00 001 000
ePosition2 = 0x10, //00 010 000
ePosition3 = 0x18, //00 011 000
ePosition4 = 0x20, //00 100 000
ePosition5 = 0x28, //00 101 000
MASK = 0x38 //00 111 000
};
public byte m_BitMask = 0;
public eDataPosition DataPosition
{
get { return (eDataPosition)(m_PacketMask | eDataPosition.MASK); }
set { m_PacketMask |= value; }
}
I get the following errors:
Operator '|' cannot be applied to operands of type 'byte' and
'TestInterface.Test.eDataPosition'
Cannot implicitly convert type 'TestInterface.Test.eDataPosition' to 'byte'
Operator '|=' cannot be applied to operands of type 'byte' and
'TestInterface.Test.eDataPosition'
I know I can cast them back and forth but why do I have to?
I tried it with and without the "Flags" attribute and with and without the
byte base-type. I get the same errors either way.
Thanks,
jim