473,385 Members | 1,615 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Hash Table problems

Opa
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.Cli entSocket.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


Nov 16 '05 #1
5 1563
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" <an*******@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.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.Cli entSocket.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

Nov 16 '05 #2
Opa
I tried SckClientHandler clientSocket = (SckClientHandler)_clientSocketHash[1036]
but the hash table does not have items. This results in an error

Any other suggestions

Thanks
Nov 16 '05 #3

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

Chris

"Opa" <an*******@discussions.microsoft.com> wrote in message
news:15**********************************@microsof t.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.Cli entSocket.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


Nov 16 '05 #4
Opa
Ok. I will try this.
Nov 16 '05 #5
Opa
This works Chris

Thanks a million.
Nov 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: pembed2003 | last post by:
Hi All, Does C++/STL have hashtable where I can do stuff like: Hashtable h<int>; h.store("one",1); h.store("two",2); and then later retrieve them like:
14
by: al | last post by:
Here's what I am trying to write a simple hash table: struct Employee { char name; int id; char department; float salary; };
4
by: Simone Battagliero | last post by:
I wrote a program which inserts and finds elements in an hash table. Each element of the table is a dinamic list, which holds all elements having the same hash value (calculated by an int...
2
by: Pieter Claassen | last post by:
But, last few questions if I may: Here is a test program that compiles and works #include <search.h> #include <stdio.h> #include <string.h> typedef struct {
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
11
by: Douglas Dude | last post by:
how much time does it take to lok for a value - key in a hash_map ? Thanks
13
by: ababeel | last post by:
Hi I am using a calloc in a hash table program on an openvms system. The calloc is used to declare the hash table char **pHashes; pHashes = calloc(hash_size,sizeof(char *)); //hash_size = 101 ...
139
by: ravi | last post by:
Hi can anybody tell me that which ds will be best suited to implement a hash table in C/C++ thanx. in advanced
23
by: raylopez99 | last post by:
A quick sanity check, and I think I am correct, but just to make sure: if you have a bunch of objects that are very much like one another you can uniquely track them simply by using an ArrayList...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.