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

A string as a Hashtable key

Hi all,

Is it ok to use a string as the key for Hashtable entries? I want to use
the name of entity in question, which I know will always be unique.
Do I have to do anything fancy equality-wise or are there any caveats I should
be aware of?

Thanks to anyone who can advise.

Kindest Regards

tce

Aug 6 '05 #1
6 3751
> Is it ok to use a string as the key for Hashtable entries?

yes, it is ok to use strings, i do it all the time. the comparison is case
sensitive, so if you want to have case insensitive keys, then drive your key
strings to upper case (or lower if you prefer).
Aug 6 '05 #2
AMercer wrote:
Is it ok to use a string as the key for Hashtable entries?


yes, it is ok to use strings, i do it all the time. the comparison is case
sensitive, so if you want to have case insensitive keys, then drive your key
strings to upper case (or lower if you prefer).


Or use a case insensitive comparison fn.
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionscaseinsensitivehashcodeprovi derclasstopic.asp>

--

www.midnightbeach.com
Aug 6 '05 #3
Jon,

It seems for me easier to use consequently
..ToLower

I hope that I don't miss something

Cor
Aug 7 '05 #4
"Cor Ligthert [MVP]" wrote:
It seems for me easier to use consequently
.ToLower

I hope that I don't miss something


Easier, maybe, but not always desirable. Using a case-insensitive
comparison function allows semantics like file names: Case doesn't
matter, but is preserved.

If I use "Jon Shemitz" as a key, I might prefer to get back "Jon
Shemitz" when I enumerate the Keys, not "jon shemitz" or "JON
SHEMITZ".

--

www.midnightbeach.com
Aug 7 '05 #5
Jon,

I don't know what program language you use, however in VBNet is for that as
well a function.

http://msdn.microsoft.com/library/de...vconstants.asp

It is usable in C# as well of course by setting a reference to the right
namespace.

Cor
Aug 7 '05 #6
"Cor Ligthert [MVP]" wrote:
I don't know what program language you use, however in VBNet is for that as
well a function.

http://msdn.microsoft.com/library/de...vconstants.asp

It is usable in C# as well of course by setting a reference to the right
namespace.


I'm not sure how that addresses the issue of preserving case, if that
is desirable. If the key is "Rip van Winkle", then proper-casing it as
"Rip Van Winkle" is just as wrong as "rip van winkle" or "RIP VAN
WINKLE".

--

www.midnightbeach.com
Aug 7 '05 #7

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

Similar topics

13
by: usgog | last post by:
I need to implement a function to return True/false whether String A contains String B. For example, String A = "This is a test"; String B = "is is". So it will return TRUE if String A includes two...
6
by: Dan V. | last post by:
I would like to create a 2D string list (2D ArrayList ???). I would like to pass in a table or query as a parameter and have both columns transform into a 2D ArrayList. When I sort the one...
6
by: Doug | last post by:
I have data that looks something like this when returned from a stored procedure (3 columns, X rows): Key1 Name1 Value1 Key1 Name2 Value2 Key1 Name3 Value3 Key1 Name4 ...
10
by: Daniel | last post by:
how to make two references to one string that stay refered to the same string reguardless of the changing value in the string?
5
by: ad | last post by:
I have a string like string myString="dog,cat,dog,tiger" I want to delete the duplication part, and make myString to "dog,cat,tiger" How can I do that?
10
by: ksrajalakshmi | last post by:
Hai , in a textbox am having text as "(20/100)+pay1*pay2" .it's a formula. and stored in a particular variable. string strformula="(20/100)+pay1*pay2" ; i've to substitute the value of the...
10
by: chrisben | last post by:
Hi, Here is the scenario. I have a list of IDs and there are multiple threads trying to add/remove/read from this list. I can do in C# 1. create Hashtable hList = Hashtable.Synchronized(new...
15
by: Ashish Khandelwal | last post by:
As MSDN is not giving us guarantee upon uniqueness of Hash Code, so could any one suggest me that how to generate a unique Hash Code for same string always, and generate different-2 Hash Code...
8
by: Ashish Khandelwal | last post by:
-----See below code, string str = "blair"; string strValue = "ABC"; string str1 = "brainlessness"; string strValue1 = "XYZ"; int hash = str.GetHashCode() ; // Returns 175803953 int hash1 =...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.