Hashtable in Chapter 5
In chapter five, the book demostrates Hashtables using the Structure Demo program. I don't entirely understand the function of one property within the CustomerCollection class:
Public ReadOnly Property EmailHashtable() As Hashtable
Get
Return _emailHashtable
End Get
End Property
I tried removing the property and replacing EmailHashtable with _emailHashtable in the rest the code and program continued to work exactly as it did before:
Public Class CustomerCollection
Inherits System.Collections.CollectionBase
Private _emailHashtable As New Hashtable
Public Shadows Sub Clear()
MyBase.Clear()
_emailHashtable.Clear()
End Sub
Public Shadows Sub RemoveAt(ByVal index As Integer)
Remove(Item(index))
End Sub
Public Sub Add(ByVal newCustomer As Customer)
Me.List.Add(newCustomer)
_emailHashtable.Add(newCustomer.Email.ToLower, newCustomer)
End Sub
Public Sub Remove(ByVal removeCustomer As Customer)
Me.List.Remove(removeCustomer)
_emailHashtable.Remove(removeCustomer.Email.ToLowe r)
End Sub
Default Public Property Item(ByVal index As Integer) As Customer
Get
Return Me.List.Item(index)
End Get
Set(ByVal Value As Customer)
Me.List.Item(index) = Value
End Set
End Property
Default Public ReadOnly Property Item(ByVal email As String) As Customer
Get
Return _emailHashtable.Item(email.ToLower)
End Get
End Property
End Class
I guess the Property could later on take on additonal code that could give it some special functionality, making the code easier to maintain? The book doesn't really talk about it either way.
|