public enum WeekDay
{
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
Sunday = 7
}
string s = WeekDay.Friday.ToString();
simple as that... unless I am misunderstanding something?
And if you only have the number:
string s = ((WeekDay)4).ToString();
UPDATE
OK, next time you should mention that you want something generic.. to use for all enums and not just that specific example. You can try this:
public static class EnumExtensions
{
public static T ToEnum<T>(this int value) where T : struct
{
return (T)(object)value;
}
public static string ToEnumName<T>(this int value) where T : struct
{
return ((T)(object)value).ToString();
}
}
Use like this:
int someEnumValue = 4;
string name = someEnumValue.ToEnumName<WeekDay>();
or:
WeekDay weekDay = someEnumValue.ToEnum<WeekDay>();
I still don't think that is really necessary though, because you still need to know the type of enum anyway... so therefore:
This: string name = ((WeekDay)someEnumValue).ToString();
and this string name = someEnumValue.ToEnumName<WeekDay>();
are equivalent... but.. whatever suits you.