Yes - you can use Enum.Parse (and Enum.TryParse as of .NET 4) to parse a string to an enum value.:
Day day = (Day) Enum.Parse(typeof(Day), "Sun");
or
Day day;
if (Enum.TryParse<Day>("Sun", out day))
{
// Success!
}
It's still somewhat ugly, mind you - quitethere's a bitcertain amount of casting involved in the first call, and the second wouldn't stop you from trying to parse to any value type.
The final reason I don't really like Parse/TryParse is that they will parse string representations of the numeric values of the enums - so "1" would successfully parse, even though it's clearly not the name of an enum value. That seems a bit clunky to me.
There's a simplernicer (IMO!) approach if you use Unconstrained Melody, a small open source project I wrote to allow generics with enum constraints. Then you'd have:
Day day = Enums.ParseName<Day>("Sun");
or
Day day;
if (Enums.TryParseName<Day>("Sun", out day))
{
// Success!
}
No casting, and you can't accidentally use it on a non-enum type. (There are various other goodies in the project, of course... description parsing etc.)