Reputation: 7829
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?
Upvotes: 2
Views: 174
Reputation: 7949
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"`
}
Upvotes: 4
Reputation:
You can cast it to enum and retreive by ToString()
:
var result = ((options)62).ToString();
Upvotes: 8