samedi 27 juin 2020

Get Enum Member by Value Attribute [duplicate]

How can I retrieve enum member using Value attribute.

public enum State
{
    [JsonIgnore] Undefined = 0,
    [EnumMember(Value = "Connecticut")] CT = 7,
    [EnumMember(Value = "Massachusetts")] MA = 33,
    [EnumMember(Value = "Maine")] ME = 19,
    [EnumMember(Value = "New Hampshire")] NH = 23
}

How would I retrieve CT using or by "Connecticut"? I am finding a lot of opposite examples (i.e. get value by member).





Aucun commentaire:

Enregistrer un commentaire