Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 22nd, 2008, 10:41 AM
Registered User
 
Join Date: Feb 2008
Location: , , .
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


  #2 (permalink)  
Old February 22nd, 2008, 04:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
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
  #3 (permalink)  
Old February 22nd, 2008, 05:15 PM
Registered User
 
Join Date: Feb 2008
Location: , , .
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


 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 03: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



All times are GMT -4. The time now is 04:20 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.