Enumertors in VB.NET
This article defines the Enumerator with a example in VB.NET.
In this article You will learn How to use Enumerators in VB.NET.
Enumerators:
-
Use enum keyword.
-
Starts with 0 and incremented by 1.
-
Enumeration is a related set of constants. They are used when working with many constants of the same type. It's declared with the Enum keyword.
For example:
enum Days as byte
Sun=1
Mon
Tue
dim d as days=days.Tue;
- Default allocation is for int and You can define the datatype.
enum Numbers as byte
ZERO
ONE
TWO
THREE
Note:
Use sizeof() operator to get size of items
Code define the Enumerator:
Module Module1
Enum Days As Byte
Sun = 1
Mon
Tue
Wed
End Enum
Class EnumTest
Public Shared Sub Main()
Dim d As Days = Days.Tue
Console.WriteLine(d)
Console.WriteLine(CInt(d))
End Sub
End Class
End Module
Output:
This article shows that the value start with the zero and is increment by 1. sun day value is define 1 and it automatically increment the value by 1 till the tue. so the tue value is 3 .