Posted by: Sourav | August 27, 2016

More Enum(getnames and getvalues)in VB,VB Teacher Sourav,Kolkata,09748184075


Option Strict On
Option Explicit On
Imports System
Module Module1

Sub Main()
Dim values() As Integer = CType([Enum].GetValues(GetType(gender)), Integer())
For Each value As Integer In values

Console.WriteLine(value)

Next

Dim names() As String = [Enum].GetNames(GetType(gender))
For Each name As String In names

Console.WriteLine(name)

Next

Dim values2() As Short = CType([Enum].GetValues(GetType(gender2)), Short())
For Each value As Short In values2

Console.WriteLine(value)

Next

Dim names2() As String = [Enum].GetNames(GetType(gender2))
For Each name As String In names2

Console.WriteLine(name)

Next

Dim gender3 As gender3 = CType(3, gender3)
Console.WriteLine(gender3)
Dim gender4 As gender4
gender4 = CType(gender3, enumindepthvb.gender4)
Console.WriteLine(gender4)
Dim num As Integer = CType(gender3.unknown, Integer)
Console.WriteLine(“gender3.unknown={0}”, num)

Dim values3() As Integer = CType([Enum].GetValues(GetType(gender3)), Integer())
For Each value As Integer In values3

Console.WriteLine(value)

Next

Console.ReadLine()

End Sub

End Module
Public Enum gender

unknown
male
female

End Enum

Public Enum gender2 As Short

unknown = 10
male = 15
female = 20

End Enum

Public Enum gender3

unknown = 10
male = 15
female = 20

End Enum
Public Enum gender4

unknown = 10
male = 15
female = 20

End Enum

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: