Enumeration In VB.NET

What is Enumeration?

Explanation

Enumeration in vb.net 2008.

Enumeration in is a collection of related set of constants that are declared using the keyword Enum Statement. All the members are of "enum" datatype and will have an numeric value that start with '0' for first element.
Syntax:

Enum enumeration name [ As data type ]
member list
End Enum

In the above syntax the enumeration name provides a unique name for the enumeration, data type can be specified if required, member list lists the members of the enumeration.
Example:

Module Module1
Enum Fruits
Orange = 1
Apple = 2
Guava = 3
End Enum
Sub Main()
Console.WriteLine("First Fruit is::"
& Fruits.Orange.ToString())
Console.WriteLine("Second Fruit is::"
& Fruits.Apple.ToString())
Console.WriteLine("Third Fruit is::"
& Fruits.Guava.ToString())
Console.ReadLine()
End Sub
End Module
Result:

First Fruit is:: Orange
Second Fruit is:: Apple
Third Fruit is:: Guava
Description:

In the above example, three enumeration members are listed under the enumeration name Fruits that have a numeric value starting from '1'.

Visual Basic Tutorial


Ask Questions

Ask Question