471,349 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,349 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 3678
> 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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by ksrajalakshmi | last post: by
15 posts views Thread by Ashish Khandelwal | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.