
In C#, Enum plays a very important role which making code more readable. In this article learn how to convert String to Enum.
How to Convert String To Enum | Convert String to Enum
This example shows how to convert enum values to a string and vice versa.
Color color = Color.Red; string str = color.ToString(); // "Red"
String to enum:
using System; string str = "Red"; Color animal = (Color)Enum.Parse(typeof(Color), str); // Color.Red Color animal = (Color)Enum.Parse(typeof(Color), str, true); // case insensitive
– Article ends here –