Posted by: Sourav | August 26, 2016

Enum example in VB,VB Teacher Sourav,Kolkata 09748184075


Option Strict On
Option Explicit On
Imports System

Module Module1

Sub Main()
Dim customers(3) As customer
customers(0) = New customer
customers(0).manipulatename = “Sourav”
customers(0).manipulategender = gender.Male

customers(1) = New customer
customers(1).manipulatename = “Sougata”
customers(1).manipulategender = gender.Female

customers(2) = New customer
customers(2).manipulatename = “Subrata”
customers(2).manipulategender = gender.unknown

For Each customer As customer In customers
If IsNothing(customer) <> True Then
Console.WriteLine(“The name is {0} “, customer.manipulatename)
Console.WriteLine(“The gender is {0} “, getgender(customer.manipulategender))
Else
End If

Next

Console.ReadLine()
End Sub

Public Function getgender(ByVal gender As gender) As String
Select Case gender

Case gender.unknown
Return “Unknown”
Case gender.Male
Return “Male”
Case gender.Female
Return “Female”
Case Else
Return “Invalid date selected”
End Select

End Function
End Module
Public Class customer
Private name As String
Public Property manipulatename() As String

Get
Return Me.name
End Get
Set(ByVal value As String)
Me.name = value
End Set
End Property
Private gender As Integer
Public Property manipulategender() As gender

Get
Return CType(Me.gender, enumvb.gender)
End Get
Set(ByVal value As gender)
Me.gender = value
End Set
End Property

End Class
Public Enum gender
unknown
Male
Female
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: