Thursday 11 July 2019

.net - Get String Name from Enum in C#

I have declared enum as below



public enum State
{
KARNATAKA = 1,
GUJRAT = 2,
ASSAM = 3,
MAHARASHTRA = 4,
GOA = 5
}


From external sources, I get the State values as either 1 or 2 or 3 or 4 or 5.



Based on the value i get, I need to look up this enum and get its string.



For Ex: If the input value is 1, I need to return KARNATAKA as string. Similarly, If the input value is 5, I need to return GOA as string.



Is there a easy way to get the string with out using CASE or IFELSE.

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...