Imports System
Imports System.Collections
Imports System.Collections.Generic
Imports System.Collections.Specialized
Public Class MainClass
Shared Sub Main(ByVal args As String())
Dim dict As New StudentListDictionary
dict.Add("111-11-1111", New Student("A", "A"))
dict.Add("333-22-3333", New Student("B", "B"))
dict.Add("444-44-4444", New Student("C", "C"))
dict.Add("555-55-5555", New Student("D", "D"))
Dim student As Student = dict.Item("111-11-1111")
Console.WriteLine(student.ToString)
End Sub
End Class
Public Class Student
Private m_FirstName As String
Private m_LastName As String
Public Sub New(ByVal first_name As String, ByVal last_name As String)
m_FirstName = first_name
m_LastName = last_name
End Sub
Public Overrides Function ToString() As String
Return m_FirstName & " " & m_LastName
End Function
End Class
Public Class StudentListDictionary
Inherits ListDictionary
' Add a Dictionary entry.
Public Shadows Sub Add(ByVal new_key As String, ByVal new_student As Student)
MyBase.Add(new_key, new_student)
End Sub
' Return an object with the given key.
Default Public Shadows Property Item(ByVal key As String) As Student
Get
Return DirectCast(MyBase.Item(key), Student)
End Get
Set(ByVal Value As Student)
MyBase.Item(key) = Value
End Set
End Property
' Return True if the Dictionary contains this Student.
Public Shadows Function Contains(ByVal key As String) As Boolean
Return MyBase.Contains(key)
End Function
' Remove this entry.
Public Shadows Sub Remove(ByVal key As String)
MyBase.Remove(key)
End Sub
End Class