Finding an enum value by its Description Attribute [duplicate]

Using the extension method described here :

Testing t = Enum.GetValues(typeof(Testing))
                .Cast<Testing>()
                .FirstOrDefault(v => v.GetDescription() == descriptionToMatch);

If no matching value is found, it will return (Testing)0 (you might want to define a None member in your enum for this value)

Leave a Comment