Wednesday, October 04, 2006

Enum Parsing

I always seem to forget how to parse an enum, so here's the code for doing it in 2.0:

enum ConfigurationType
        {
            Internal,
            WebConfigXml,
            Win32Xml
        };

string strConfigType = System.Configuration.ConfigurationSettings.AppSettings["ConfigurationType"].ToString();
ConfigurationType configType = (ConfigurationType)Enum.Parse(typeof(ConfigurationType), strConfigType);

No comments:

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Fixes to common .NET problems, as well as information on .NET features and solutions to common problems that are not language-specific.

Z