I have a enum containing the following (for example):
In my code I use
The following solution works (compiles and runs). I see two issues:
You would have to make sure the enums are in sync. (An automated test can do that for you.)
You would be relying in the fact that enums are not type safe in .NET.
enum Country
{
UnitedKingdom = 0,
UnitedStates = 1,
France = 2,
Portugal = 3
}
enum CountryCode
{
UK = 0,
US = 1,
FR = 2,
PT = 3
}
void Main()
{
string countryCode = ((CountryCode)Country.UnitedKingdom).ToString();
Console.WriteLine(countryCode);
countryCode = ((CountryCode)Country.Portugal).ToString();
Console.WriteLine(countryCode);
}