Wrox Programmer Forums
|
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 4th, 2005, 09:19 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
 
Old February 5th, 2005, 06:59 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

You are correct in your assumptions. The EmailHashtable property is used internally in the CustomerCollection class but has been defined as public so it could be used by a consumer of this class to get the entire email hash table.

The original author did not explain this well nor did they provide an example of using this property from the code in the form.

Thearon





Similar Threads
Thread Thread Starter Forum Replies Last Post
Hashtable ajit Java Basics 1 July 11th, 2006 01:25 AM
Hashtable Scott Rider General .NET 7 July 3rd, 2005 02:25 AM
Hashtable mahulda General .NET 2 August 2nd, 2004 07:49 AM
Hashtable in C# sachin-csharp .NET Framework 2.0 0 July 28th, 2004 01:45 AM
about hashtable csc820203 C# 1 July 11th, 2004 07:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.