What's the best practice way to convert enum to string?
- by dario
Hi.
I have enum like this:
public enum ObectTypes
{
TypeOne,
TypeTwo,
TypeThree,
...
TypeTwenty
}
then I need to convert this enum to string. Now Im doing this that way:
public string ConvertToCustomTypeName(ObjectTypes typeObj)
{
string result = string.Empty;
switch (typeObj)
{
case ObjectTypes.TypeOne: result = "This is type T123"; break;
case ObjectTypes.TypeTwo: result = "This is type T234"; break;
...
case ObjectTypes.TypeTwenty: result = "This is type last"; break;
}
return result;
}
Im quite sure that there is better way do do this, Im looking for some good practice solution.
Thanks in advance.