Posted by: Sourav | August 21, 2016

A more practical example on Delegates using VB,VB Teacher Sourav,09748184075


Option Strict On
Option Explicit On
Imports System
Imports System.Collections.Generic
Imports ListExample.Employee

Module Module1

Sub Main()
Dim count As Integer = 0

Dim emplist As New List(Of Employee)
emplist.Add(New Employee())

emplist(count).manipulateid = 0
emplist(count).manipulatename = “Sourav”
emplist(count).manipulateexperience = 5
emplist(count).manipulatesalary = 5000
count += 1

emplist.Add(New Employee())

emplist(count).manipulateid = 1
emplist(count).manipulatename = “Sougata”
emplist(count).manipulateexperience = 5
emplist(count).manipulatesalary = 5000
count += 1
emplist.Add(New Employee())

emplist(count).manipulateid = 2
emplist(count).manipulatename = “Subrata”
emplist(count).manipulateexperience = 6
emplist(count).manipulatesalary = 6000

count += 1
emplist.Add(New Employee())

emplist(count).manipulateid = 3
emplist(count).manipulatename = “Subir”
emplist(count).manipulateexperience = 2
emplist(count).manipulatesalary = 2000

Dim ispromotable As ispromotable = New ispromotable(AddressOf promote)

Dim emp1 As Employee = New Employee
emp1.promoteemployee(emplist, ispromotable)
Console.ReadLine()
End Sub
Function promote(ByVal emp As Employee) As Boolean
If emp.manipulateexperience >= 5 Then
Return True
Else
Return False

End If
End Function
End Module

Public Class Employee
Private id As Integer
Private name As String
Private salary As Integer
Private experience As Integer

Public Property manipulateid As Integer
Set(ByVal id As Integer)
Me.id = id

End Set
Get
Return Me.id

End Get

End Property

Public Property manipulatename As String
Set(ByVal name As String)
Me.name = name
End Set
Get
Return Me.name

End Get

End Property

Public Property manipulatesalary As Integer
Set(ByVal salary As Integer)
Me.salary = salary

End Set
Get
Return Me.salary

End Get

End Property
Public Property manipulateexperience As Integer
Set(ByVal experience As Integer)
Me.experience = experience

End Set
Get
Return Me.experience

End Get

End Property

Delegate Function ispromotable(ByVal emp As Employee) As Boolean

Public Sub promoteemployee(ByVal employeelist As List(Of Employee), ByVal iseligibletopromote As ispromotable)

For Each empobj As Employee In employeelist
If iseligibletopromote(empobj) = True Then
Console.WriteLine(empobj.manipulatename & ” got promoted”)

End If
Next

End Sub

End Class

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: