Given the C# enum:
public enum options: byte
{
yes = 0,
no = 22,
maybe = 62,
foscho = 42
}
How do you retrieve the String 'maybe' if given the byte 62?
Given the C# enum:
public enum options: byte
{
yes = 0,
no = 22,
maybe = 62,
foscho = 42
}
How do you retrieve the String 'maybe' if given the byte 62?
You can cast it to enum and retreive by ToString()
:
var result = ((options)62).ToString();
var stringValue = Enum.GetName(typeof(options), 62); // returns "maybe"
Which you might also want to wrap in a check:
if (Enum.IsDefined(typeof(options), 62))
{
var stringValue = Enum.GetName(typeof(options), 62); // returns "maybe"`
}