Hi jllouis,
Even tho you write an enumeration value in code kind of looking like a string and they can appear the same when printed to the screen, strings and enumerations are two different types of object and behave in different ways. In fact an enumeration is really a number that can conveniently be used in code using text.
So enum Color.Red cannot be used the same way as string "Red".
A common reason why you might want to convert from one to the other could be to read configuration values from a file to use in a program.
For example, a windows application may read in a config value to set the background color of the form:
Code:
// read string from app.config text file ("Red")
string backColorString = ConfigurationManager.AppSettings["FormBackground"];
// convert to a Color Enum (Color.Red)
System.Drawing.Color backColorEnum = (System.Drawing.Color)Enum.Parse(
typeof(System.Drawing.Color), backColorString
);
// the BackColor property is of type Enum Color, so use our converted value
MyForm.BackColor = backColorEnum;
// this will error - you cant set the BackColor to a string value
MyForm.BackColor = backColorString;