'
' Title: Enumeration of Constants in VB.NET
' Example with and without explicit values
'
Imports System
' ---------------------------------------------
' Enum WITHOUT explicit values
' VB.NET automatically assigns 0, 1, 2...
' ---------------------------------------------
Enum Color
Red ' 0
Green ' 1
Blue ' 2
End Enum
' ---------------------------------------------
' Enum WITH explicit and mixed values
' ---------------------------------------------
Enum Status
OK = 1 ' 1
Warning = 5 ' 5
Err ' 6 (auto: previous + 1)
Critical = 10 ' 10
End Enum
Module Program
Sub Main()
Console.WriteLine("Enum without explicit values:")
Console.WriteLine("Red = " & CInt(Color.Red))
Console.WriteLine("Green = " & CInt(Color.Green))
Console.WriteLine("Blue = " & CInt(Color.Blue))
Console.WriteLine()
Console.WriteLine("Enum with explicit and mixed values:")
Console.WriteLine("OK = " & CInt(Status.OK))
Console.WriteLine("Warning = " & CInt(Status.Warning))
Console.WriteLine("Err = " & CInt(Status.Err))
Console.WriteLine("Critical = " & CInt(Status.Critical))
End Sub
End Module
' run:
'
' Enum without explicit values:
' Red = 0
' Green = 1
' Blue = 2
'
' Enum with explicit and mixed values:
' OK = 1
' Warning = 5
' Err = 6
' Critical = 10
'