Q:

C# program to demonstrate the GetValues() method of Enum class

belongs to collection: C# Enum Class Programs

0

Syntax:

    Array Enum.GetValues(Type enumType);

Parameter:

Here we pass an instance of a specified enum.

Return value:

This method returns an array of the values of the constants in the specified enum.

Exceptions:

  • System.ArgumentException
  • System.ArgumentNullException
  •  

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

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 . . .

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# program to demonstrate the GetUnderlyingType() ... >>
<< C# program to demonstrate the GetTypeCode() method...