The source code to demonstrate the GetValues() 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()
{
Console.WriteLine("Values of Directions:");
foreach (var val in Enum.GetValues(typeof(Directions)))
{
Console.WriteLine("{0,3} 0x{0:X8} {1}",(int)val, ((Directions)val));
}
}
}
Output:
Values of Directions:
0 0x00000000 EAST
1 0x00000001 WEST
2 0x00000002 NORTH
3 0x00000003 SOUTH
Press any key to continue . . .
Program:
The source code to demonstrate the GetValues() method of Enum class is given below. The given program is compiled and executed successfully.
Output: