You could also make an extension method...
public static class EnumExtensions
{
public static string Description(this Enum e)
{
return e.GetType().GetField(e.ToString()).GetCustomAttributes(typeof(DescriptionAttribute), false) as DescriptionAttribute[])[0].Description;
}
}
Then the code to use is as simple as:
public enum SampleEnum
{
[Description("Value 1")]
One,
[Description("Value 2")]
Two,
[Description("Value 3")]
Three
}
SampleEnum val = SampleEnum.One;
string desc = val.Description();
I studied Software Engineering at Milwaukee School of Engineering for 2 years before switching to Management of Information Systems for a more business oriented approach. I've been developing software since the age of 14, and have waded through languages such as QBasic, TrueBasic, C, C++, Java, VB6, VB.NET, C#, etc. I've been developing professionally since 2002 in .NET.