Home »
VB.Net »
VB.Net Programs
VB.Net program to print the name of Enum constants
By Nidhi Last Updated : November 16, 2024
How to print the name of Enum constants in VB.Net?
Here, we will create an Enum of Colors and then print the name of the Enum constant on the console screen.
Program/Source Code:
The source code to print the name of Enum constants is given below. The given program is compiled and executed successfully.
VB.Net code to print the name of Enum constants
'VB.Net program to print the name of Enum constants.
Module Module1
Enum Colors
RED
GREEN
YELLOW
BLUE
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:
RED
GREEN
YELLOW
BLUE
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1. Here, we created an Enum Colors that contains the name of colors. In the Main() function, we printed the name of Enum constants on the console screen.
VB.Net Basic Programs »