// Convert values to and from strings. private void Form1_Load(object sender, EventArgs e) { foreach (string value in Enum.GetNames(typeof(MealType))) { // Get the enumeration's value. MealType meal = (MealType)Enum.Parse(typeof(MealType), value);
The code uses Enum.GetNames to get strings representing the MealType values. For each of those strings, it uses Enum.Parse to convert the string into a MealType value. It then displays the value as an integer and in its string form.
Comments