473,322 Members | 1,911 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,322 software developers and data experts.

Hashtable Key limit

Is there a limit to the size of a key for a Hashtable. I am adding items to
a hashtable using a string for the key and it seems that when my key is 16
characters long the indexer does not work properly. If I truncate the key
to be 12 characters the indexer works.

Also is there a better way to build a key for a string, should I convert the
string to a numeric value then add it?

and if so how do I go about converting a string to a numeric value.
Nov 16 '05 #1
2 3327
Not sure I understand. GetHashCode returns an int regardless of length.
Does this help?

Hashtable ht = new Hashtable();
ht.Add("This is my very long string key", "one");
ht.Add("This is small", "two");
ht.Add("This", "three");
foreach(string s in ht.Keys)
{
Console.WriteLine("Key:"+s);
}
Console.WriteLine("Value:" + ht["This is my very long string key"]);

If not, please supply small sample of code that shows your issue. Cheers!

--
William Stacey, MVP

"MFRASER" <mf*****@henwoodenergy.com> wrote in message
news:uo**************@TK2MSFTNGP10.phx.gbl...
Is there a limit to the size of a key for a Hashtable. I am adding items to a hashtable using a string for the key and it seems that when my key is 16
characters long the indexer does not work properly. If I truncate the key
to be 12 characters the indexer works.

Also is there a better way to build a key for a string, should I convert the string to a numeric value then add it?

and if so how do I go about converting a string to a numeric value.


Nov 16 '05 #2
No, there is no such limit.

You should take a look at System.Convert for conversion methods.

Bruno.

"MFRASER" <mf*****@henwoodenergy.com> a écrit dans le message de
news:uo****************@TK2MSFTNGP10.phx.gbl...
Is there a limit to the size of a key for a Hashtable. I am adding items to a hashtable using a string for the key and it seems that when my key is 16
characters long the indexer does not work properly. If I truncate the key
to be 12 characters the indexer works.

Also is there a better way to build a key for a string, should I convert the string to a numeric value then add it?

and if so how do I go about converting a string to a numeric value.

Nov 16 '05 #3

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

Similar topics

2
by: MFRASER | last post by:
Is there a limit to the size of a key for a Hashtable. I am adding items to a hashtable using a string for the key and it seems that when my key is 16 characters long the indexer does not work...
4
by: Gary Davis | last post by:
Once a day or so, I receive an error on a fairly active website that calls this StrMixed.cs method constructor. 99% of the time there is no exception: System.Web.HttpUnhandledException:...
5
by: francois | last post by:
First of all I would to to apologize for resending this post again but I feel like my last post as been spoiled Here I go for my problem: Hi, I have a webservice that I am using and I would...
5
by: Cyrus | last post by:
I have a question regarding synchronization across multiple threads for a Hashtable. Currently I have a Threadpool that is creating worker threads based on requests to read/write to a hashtable....
33
by: Ken | last post by:
I have a C# Program where multiple threads will operate on a same Hashtable. This Hashtable is synchronized by using Hashtable.Synchronized(myHashtable) method, so no further Lock statements are...
16
by: Sreekanth | last post by:
Hello, Is there any better collection than HashTable in terms of performance, when the type of the key is integer? Regards, Sreekanth.
3
by: Fred | last post by:
I'm trying to build a hashtable and a arraylist as object value I'm not able to retrieve stored object from the hashtable. Hashtable mp = new Hashtable(); // THE HASHTABLE ArrayList...
2
by: PAzevedo | last post by:
I have this Hashtable of Hashtables, and I'm accessing this object from multiple threads, now the Hashtable object is thread safe for reading, but not for writing, so I lock the object every time I...
8
by: chrisben | last post by:
Hi, If I am not sure how many items will be in my Hashtable/ArrayList dynamically (multiple threads can add/remove/check the item), however, I can estimate the total number will not exceed...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.