Home >>VB.Net Built-in Functions >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
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.