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 22nd, 2008, 10:41 AM
Registered User
 
Join Date: Feb 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Question on hastable code

I have a question about the hastable code below. I'm not sure what the private member _emailHashtable does in this code. What is the Public ReadOnly Property EmailHashtable returning? The code works the same if instead of using this Public ReadOnly Property we used _emailHashtable everywhere. I don't understand why we needed both _emailHashtable and the Public Property EmailHashtable. When Public ReadOnly Property EmailHashtable returns _emailHashtable what is in this value? Is anything assigned to it?


Inherits System.Collections.CollectionBase
' members...
Private _emailHashtable As New Hashtable()

' Add - add a customer...
Public Sub Add(ByVal newCustomer As Customer)
   Me.List.Add(newCustomer)

  ' add to the hashtable...
   EmailHashtable.Add(newCustomer.Email, newCustomer)
End Sub

' EmailHashtable - return the e-mail hashtable...
Public ReadOnly Property EmailHashtable() As Hashtable
  Get
     Return _emailHashtable ' What is retunred here???????
  End Get
End Property

Default Public ReadOnly Property Item(ByVal email As String) _
As Customer
Get
Return EmailHashtable.Item(email)
End Get
End Property

End Class


 
Old February 22nd, 2008, 04:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Public properyt only exposes the variable _emailHashTable, which I assume is created in the constructor. You need the underlying hashtable to store the data somewhere; the property only exposes it to the user of the class. So whomever uses the class can access the EmailHashtable property, which returns a reference to the _emailHashtable.

Does that make sense?

Brian
 
Old February 22nd, 2008, 05:15 PM
Registered User
 
Join Date: Feb 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yeah, I do understand that. I just don’t see where the _emailHashtable gets assigned anywhere in the code. In the Add Sub it’s the EmailHashtable Property that gets added to. I expected that the _emailHashtable would get added to and then the EmailHashtable Property would return the value.

Thank you for your response







Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about a piece of code chobo2 C# 2008 aka C# 3.0 8 November 30th, 2008 11:53 AM
Can't intialize a Hastable in Constructor chobo2 C# 2008 aka C# 3.0 2 October 8th, 2008 02:08 PM
Default code question Fikus C# 2005 3 November 27th, 2006 05:57 PM
Answer this code question jaimini VB.NET 2002/2003 Basics 3 November 27th, 2004 07:10 AM





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