Home >>VB.Net Built-in Functions >VB.Net program to print the name of Enum constants

VB.Net program to print the name of Enum constants

Write a VB.Net program to print the name of Enum constants

We'll create an Enum of Colors here, and then print the Enum constant's name on the console screen.

Program :

Below is the source code for printing the name of Enum constants. The program given is compiled and successfully executed.

'VB.Net program to print the name of Enum constants.


Module Module1
    Enum Colors
        WHITE
        ORANGE
        RED
        YELLOW
    End Enum
    Sub Main()
        Console.WriteLine("Enum constant names: ")
        For Each color As String In [Enum].GetNames(GetType(Colors))
            Console.WriteLine(color)
        Next
    End Sub
End Module
	
Output:
Enum constant names:
WHITE
ORANGE
RED
YELLOW
Explanation:

We created a Module1 module in the program above. Here, we have created an Enum Color that includes color names. We printed the name of Enum constants in the Main() function on the console screen.


No Sidebar ads