Re: Hash Table problems
From: Bob Grommes (bob_at_bobgrommes.com)
Date: 05/08/04
- Next message: Christoph Nahr: "Re: Faster than GDI+"
- Previous message: Thomas Due: "Re: checkbox in side a list box"
- In reply to: Opa: "Hash Table problems"
- Next in thread: Opa: "Re: Hash Table problems"
- Reply: Opa: "Re: Hash Table problems"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Christoph Nahr: "Re: Faster than GDI+"
- Previous message: Thomas Due: "Re: checkbox in side a list box"
- In reply to: Opa: "Hash Table problems"
- Next in thread: Opa: "Re: Hash Table problems"
- Reply: Opa: "Re: Hash Table problems"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|