What's the best practice way to convert enum to string?
Posted
by dario
on Stack Overflow
See other posts from Stack Overflow
or by dario
Published on 2010-03-31T21:57:54Z
Indexed on
2010/03/31
22:03 UTC
Read the original article
Hit count: 365
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.
© Stack Overflow or respective owner