×

VB.Net Programs

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

By Nidhi Last Updated : November 16, 2024

How to print the explicitly initialized values of Enum constants in VB.Net?

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

Program/Source Code:

The source code to print the explicitly initialized values of Enum constants is given below. The given program is compiled and executed successfully.

VB.Net code to print the explicitly initialized values of Enum constants

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

Module Module1
    Enum Colors
        RED = 5
        GREEN
        YELLOW = 10
        BLUE
    End Enum

    Sub Main()
        Console.WriteLine("Values of Enum constants are: ")
        Console.WriteLine("RED      : " & CInt(Colors.RED))
        Console.WriteLine("GREEN    : " & CInt(Colors.GREEN))
        Console.WriteLine("YELLOW   : " & CInt(Colors.YELLOW))
        Console.WriteLine("BLUE     : " & CInt(Colors.BLUE))
    End Sub
End Module

Output:

Values of Enum constants are:
RED      : 5
GREEN    : 6
YELLOW   : 10
BLUE     : 11
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 explicitly initialized value of Enum constants on the console screen.

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.