Mono Class Library: System.Enum Overview | MembersSystem.Enum.Parse Method |
Converts the specified string representation of one or more enumerated constants of a specified enumeration type to an equivalent enumerated object. [Edit]
|
- enumType
- The Type of an enumeration. [Edit]
- value
- A string containing one or more names or a single numeric value to convert. If the string contains more than one name, each name is required to be separated by a comma (','). The names are parsed in a case-sensitive manner. The names or number can be surrounded by any amount of white space. [Edit]
- value
- Documentation for this section has not yet been entered. [Edit]
A object of type enumType whose values are represented by value. [Edit]
Type Reason ArgumentNullException enumType or value is a null reference. [Edit] ArgumentException enumType is not a Type that describes a Enum.
-or-
value is either equal to string.Empty or contains only white space.
-or-
value represents one or more names, and at least one name represented by value is not of type enumType.
[Edit]
This version of Enum.Parse(Type, string) is equivalent to Enum.Parse(Type, string) (enumType, value, false). [Edit]
The following example demonstrates the Enum.Parse(Type, string) method.
C# Example using System; public enum Colors { Red = 1, Blue = 2 } public class enumTest { public static void Main() { object o = Enum.Parse( typeof (Colors), "Red, Blue"); Type oType = o.GetType(); Console.WriteLine("The type of the object returned is {0}",oType.ToString()); Array values = Enum.GetValues(oType); foreach (Colors c in values) { Console.WriteLine(Enum.Format(oType,c,"D")); } } }The output is
The type of the object returned is Colors
1
2
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0