String To Enum Conversion [C#]
Here is an example to shows how to convert enum values to string and vice-verca.
Enum to string
To convert enum to string use simply Enum.ToString method.
Status status= Status.Present;
string str = status.ToString(); // "Present"
String to enum
string str = "apsent";
Status status = (Status)Enum.Parse(typeof(Status), str); // Status.Present
Status status = (Status)Enum.Parse(typeof(Status), str, true); // case insensitive
Here is an example to shows how to convert enum values to string and vice-verca.
Enum to string
To convert enum to string use simply Enum.ToString method.
Status status= Status.Present;
string str = status.ToString(); // "Present"
String to enum
string str = "apsent";
Status status = (Status)Enum.Parse(typeof(Status), str); // Status.Present
Status status = (Status)Enum.Parse(typeof(Status), str, true); // case insensitive