Imports System
Imports System.Collections
Class Employee
Public Name As String
Public Wage As Double
Public Sub New(ByVal N As String, ByVal W As Double)
Name = N
Wage = W
End Sub
Public Sub PayRaise(ByVal Amount As Double)
Wage += Amount
End Sub
Public Overrides Function ToString() As String
Return Name & " " & Wage
End Function
End Class
Class Employer
Private MEmployees As Hashtable
Public Sub New()
MEmployees = New Hashtable()
End Sub
Public Property Employee(ByVal ID As Integer) As Employee
Get
Dim TheObject As Object
TheObject = MEmployees.Item(ID)
Return CType(TheObject, Employee)
End Get
Set(ByVal Value As Employee)
MEmployees.Item(ID) = Value
End Set
End Property
End Class
Module Test
Sub Main()
Dim Employer As New Employer()
Employer.Employee(1) = New Employee("A", 25000)
Employer.Employee(2) = New Employee("J", 35000)
Employer.Employee(3) = New Employee("T", 17000)
Employer.Employee(4) = New Employee("E", 16500)
Dim ID As Integer = 3
Dim Who As Employee
Who = employer.Employee(ID)
If Who Is Nothing Then
Console.WriteLine("Unrecognized ID: {0}", ID)
Else
Console.WriteLine("Employee details: {0}", Who)
End If
End Sub
End Module
|