ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to print the name of Enum constants

Here, we are going to learn how to print the name of Enum constants in VB.Net?
Submitted by Nidhi, on December 21, 2020

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 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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.