I have declared the following Enum:
public enum AfpRecordId
{
BRG = 0xD3A8C6,
ERG = 0xD3A9C6
}
and i want to retrieve the enum object from is value:
private AfpRecordId GetAfpRecordId(byte[] data)
{
...
}
Call Examples:
byte[] tempData = new byte { 0xD3, 0xA8, 0xC6 };
AfpRecordId tempId = GetAfpRecordId(tempData);
//tempId should be equals to AfpRecordId.BRG
I would also like to use linq or lambda, only if they can give better or equals performance.
Simple:
int(either manually, or by creating a four byte array and usingBitConverter.ToInt32)inttoAfpRecordIdToStringon the result if necessary (your subject line suggests getting the name, but your method signature only talks about the value)For example:
You can use
Enum.IsDefinedto check whether the given data is actually a valid ID.As for performance – check whether something simple gives you good enough performance before you look for something faster.