Microsoft

Blog Categories

Subscribe to RSS feed

Archives

Parsing a String to an Enum

Here is a generic extension method to get back an enum value from a string. It improves upon the Enum.Parse method by doing the following: 1) it encapsulates the cast of the value to the enum type; 2) supports an optional case-insensitive search; and 3) returns a boolean to indicate success or failure (rather than throw an exception).


Leave a Reply