Declare enum as hex.
I want to compare this enum to the value of a byte array.
An enum declared in hex.
enum ByteArrayType
{
None = 0x0000,
OK = 0x4F4B,
NK = 0x4E4B,
}
my thoughts
byte[] byteOri = { 0x4F, 0x4B };
ByteArrayType typeSelect = ByteArrayType.OK;
//Exception
typeSelect == (ByteArrayType)byteOri
//False
(short)typeSelect == BitConverter.ToInt16(byteOri)
//False
byteOri.Equals(BitConverter.GetBytes((short)typeSelect))
I found the 'string -> cast' method.
(ByteArrayType)Enum.Parse(typeof(ByteArrayType), ASCIIEncoding.Default.GetString(byteOri));
but the way i want
It's not a way to turn it into a string.
Is there any other way?