The source code to demonstrate the use of Parse() method of Enum class is given below. The given program is compiled and executed successfully.
using System;
class Sample
{
enum Directions { EAST=0,WEST=1,NORTH=2,SOUTH=3};
//Entry point of Program
static public void Main()
{
Directions dir;
//Parse string to objects then
//we convert it to Enum objects
dir = (Directions)Enum.Parse(typeof(Directions), "1");
Console.WriteLine(Enum.GetName(typeof(Directions),dir));
//Parse string to objects then
//we convert it to Enum objects with ignore case
dir = (Directions)Enum.Parse(typeof(Directions), "3",true);
Console.WriteLine(Enum.GetName(typeof(Directions), dir));
}
}
Program:
The source code to demonstrate the use of Parse() method of Enum class is given below. The given program is compiled and executed successfully.
Output: