Hash Table problems

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi Guys

I'm having trouble getting a value from a hash table based on a key that I have added
The key is the handle to a socket and the value is an instance of a class called SckClientHandler
Class SckClientHandler has a ClientSocket property which is a valid Socket object

Here I add to the hash table
_clientSocketHash.Add((int)objSckClientHandler.ClientSocket.Handle, objSckClientHandler

where objSckClientHandler is an instance of SckClientHandler
the handle in my test run is 1036

when try to inspect the hash table by the key
_clientSocketHash["1036"

I get an error stating: function '_clientSocketHash.get_Item' evaluated and returned nul

The debugger shows

- _clientSocketHash {Count=1} System.Collections.Hashtabl
+ [(short)1036] {WTP.Server.SckClientHandler} System.Objec

I know the object was added to the hash table, but I don't know how to get a reference to i

I also trie
object hashTableObject = _clientSocketHash["1036"];
SckClientHandler clientSocket =(SckClientHandler)hashTableObject
but, I get a null object

What is going on here

Thanks a lo
 
Your last attempt was correct, although the extra assignment to
hashTableObject is not needed, and you're referencing the key as a string
instead of as an int (you put it in there as an int). Try this:

SckClientHandler clientSocket = (SckClientHandler)_clientSocketHash[1036];

There is no such key as "1036", but I'll bet there IS a 1036, and then you
won't get a null reference from the indexer.

--Bob
 
I tried SckClientHandler clientSocket = (SckClientHandler)_clientSocketHash[1036]
but the hash table does not have items. This results in an error

Any other suggestions

Thanks
 
The problem might be that you are adding the key as an int, but trying to
get access to it using a string.

Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top