472,960 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 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 3737
> 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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

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.