Ad space (banner)
๐Ÿ”ทVB.NET Lessons
Lesson 41 / 68

The basics of enums

This lesson covers the basics of VB.NET's Enum, with the aim of handling a fixed set of options under readable names.

Enum ... End Enum defines an enumerated type representing a fixed set of options. Named options make the intent of the code far easier to read than bare numbers or strings.

The sample code defines three options — Red, Green, Blue — with Enum Color and assigns one to a variable as Color.Red. Note [Enum].GetNames(GetType(Color)), which lists every name in the enum.

A common early stumble is that an Enum is backed by integers underneath. It displays as a name, but consecutive integers starting at 0 are assigned internally — knowing that saves surprises.

In professional work, enums are used for fixed sets of options — order status (pending, processing, complete), days of the week, traffic light colours — and they raise readability considerably.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช This site can't compile or run VB.NET directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ€” nothing is sent anywhere).

Ad space (banner)
Ad space (in-article)