Re: Hash Table problems

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Bob Grommes (bob_at_bobgrommes.com)
Date: 05/08/04


Date: Sat, 8 May 2004 13:20:12 -0700

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

"Opa" <anonymous@discussions.microsoft.com> wrote in message
news:15DA8164-7E19-4552-85B4-76DBB178A51C@microsoft.com...
> 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 null
>
> The debugger shows:
>
> - _clientSocketHash {Count=1} System.Collections.Hashtable
> + [(short)1036] {WTP.Server.SckClientHandler} System.Object
>
> I know the object was added to the hash table, but I don't know how to get
a reference to it
>
> I also tried
> object hashTableObject = _clientSocketHash["1036"];
> SckClientHandler clientSocket =(SckClientHandler)hashTableObject;
> but, I get a null object.
>
> What is going on here?
>
> Thanks a lot



Relevant Pages

  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: hash two keys to one index
    ... What goes into the map are pairs of (reference to key, ... When I insert an object into the hash table, I pass in ... void insert(Object obj, int hash) throws HashTableFull ... int probe = 0; ...
    (comp.lang.java.programmer)
  • Re: Net::SFTP::Attributes
    ... when I ask a simple question on the correct usage of a module I would ... If $subref is specified, for each entry in the directory, $subref will ... be called and given a reference to a hash with three keys: ...
    (comp.lang.perl.modules)
  • Re: [PATCH] Make futex waiters take an mm or inode reference
    ... Make futex waiters take an mm or inode reference ... Rusty Russell wrote: ... +static inline void drop_key_refs ... -static int futex_wake ...
    (Linux-Kernel)
  • Re: Hashes of Hashes
    ... group = STRING ... If I swap the order of the declarations, then all of the keys for the ... hash that is referenced by $Data. ... This is known as a "symbolic reference" - using the ...
    (perl.beginners)