Getting the string value of any given enum is as simple as:
Electronic electronic = Electronic.Breakbeat;
// value = "Breakbeat";
string value = electronic.ToString();
Where Electronic is an Enum declared like this:
public enum Electronic
{
AcidHouse,
Ambient,
BigBeat,
Breakbeat,
Dance,
Demo,
Disco,
Downtempo,
DrumandBass,
Electro,
Garage,
HardHouse,
Houe,
IDM,
Jungle,
Progressive,
Techno,
Trance,
Tribal,
TripHop,
}
Also, if you want to get the count of items in an enum in Silverlight you will have to create your version of Enum.GetValues so this method is not included in the framework for the Win7 Mobile.
public static IEnumerable<T> GetValues<T>()
{
Type type = typeof(T);
if (!type.IsEnum)
{
// throw Exception
}
FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Static);
foreach (var item in fields)
{
yield return (T)item.GetValue(null);
}
}
int length = GetValues<Electronic>().Count();
Oh, and Merry Christmas everyone!!
Thanks,
–Mike







