Avoid space
on your enum
enum Coolness : int
{
NotSoCool = 1,
VeryCool = 2,
Supercool = 3
}
To get the value in text, try this:
string enumText = ((Coolness)1).ToString()
If you want a friendly description for each item of enum, try using the Description
attribute, for sample:
enum Coolness : int
{
[Description("Not So Cool")]
NotSoCool = 1,
[Description("Very Cool")]
VeryCool = 2,
[Description("Super Cool")]
Supercool = 3
}
And to read this attribute, you could use a method like this:
public class EnumHelper
{
public static string GetDescription(Enum @enum)
{
if (@enum == null)
return null;
string description = @enum.ToString();
try
{
FieldInfo fi = @enum.GetType().GetField(@enum.ToString());
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (attributes.Length > 0)
description = attributes[0].Description;
}
catch
{
}
return description;
}
}
And use it:
string text = EnumHelper.GetDescription(Coolness.SuperCool);