Home >>VB.Net Built-in Functions >VB.Net program to print explicitly initialized values of Enum

VB.Net program to print explicitly initialized values of Enum

Write a VB.Net program to print the explicitly initialized values of Enum constants

Here, we create an Enum of Colors and then print the directly initialized Enum constant values on the screen of the console.

Program :

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

'VB.Net program to print the explicitly

'initialized values of Enum constants.


Module Module1
    Enum Colors
        WHITE = 5
        ORANGE
        RED = 10
        YELLOW
    End Enum
    Sub Main()
        Console.WriteLine("Values of Enum constants are: ")
        Console.WriteLine("WHITE      : " & CInt(Colors.WHITE))
        Console.WriteLine("ORANGE    : " & CInt(Colors.ORANGE))
        Console.WriteLine("RED   : " & CInt(Colors.RED))
        Console.WriteLine("YELLOW     : " & CInt(Colors.YELLOW))
    End Sub
End Module

	
Output:
WHITE : 5
ORANGE : 6
RED : 10
YELLOW : 11
Explanation:

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


No Sidebar ads