473,325 Members | 2,342 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,325 software developers and data experts.

Creating a case-insensitive Hashtable in v2

Hi,

In v1.x, I used to use the following code to create a case-insensitive
Hashtable:

Hashtable MyHashtable = new
Hashtable(CaseInsensitiveHashCodeProvider.Default,
CaseInsensitiveComparer.Default);

In v2, this generates the following warnings:

Warning 1 'System.Collections.CaseInsensitiveHashCodeProvide r' is obsolete:
'Please use StringComparer instead.
Warning 4
'System.Collections.Hashtable.Hashtable(System.Col lections.IHashCodeProvider,
System.Collections.IComparer)' is obsolete: 'Please use
Hashtable(IEqualityComparer) instead.

However, when I go to the online Help for Hashtable, that's pretty much the
code it still suggests.

Can anyone please tell me the v2 way of creating a case-insensitive
Hashtable?

Any assistance gratefully received.

Mark
Feb 19 '06 #1
5 8530
Mark Rae <ma**@markN-O-S-P-A-M.co.uk> wrote:
In v1.x, I used to use the following code to create a case-insensitive
Hashtable:

Hashtable MyHashtable = new
Hashtable(CaseInsensitiveHashCodeProvider.Default,
CaseInsensitiveComparer.Default);

In v2, this generates the following warnings:

Warning 1 'System.Collections.CaseInsensitiveHashCodeProvide r' is obsolete:
'Please use StringComparer instead.
Warning 4
'System.Collections.Hashtable.Hashtable(System.Col lections.IHashCodeProvider,
System.Collections.IComparer)' is obsolete: 'Please use
Hashtable(IEqualityComparer) instead.

However, when I go to the online Help for Hashtable, that's pretty much the
code it still suggests.

Can anyone please tell me the v2 way of creating a case-insensitive
Hashtable?


Well, the preferred way of creating a map in 2.0 is usually to use
Dictionary<TKey, TValue>, passing in an IEqualityComparer<T>. In this
case, you would create a Dictionary<string,Foo> (where Foo is whatever
type your values are) and pass in an instance of StringComparer - eg
StringComparer.OrdinalIgnoreCase or
StringComparer.CurrentCultureIgnoreCase.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 19 '06 #2
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Well, the preferred way of creating a map in 2.0
A map...???
is usually to use Dictionary<TKey, TValue>


So we don't use a Hashtable any more...?
Feb 19 '06 #3
Mark Rae <ma**@markN-O-S-P-A-M.co.uk> wrote:
Well, the preferred way of creating a map in 2.0


A map...???


A map from keys to values.
is usually to use Dictionary<TKey, TValue>


So we don't use a Hashtable any more...?


Not most of the time. Think of Dictionary<TKey, TValue> as a strongly-
typed version of Hashtable.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Feb 20 '06 #4
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
> Well, the preferred way of creating a map in 2.0


A map...???


A map from keys to values.


Oh right, I see now...
> is usually to use Dictionary<TKey, TValue>


So we don't use a Hashtable any more...?


Not most of the time. Think of Dictionary<TKey, TValue> as a strongly-
typed version of Hashtable.


OK, thanks for that. I'm still getting to grips with v2, so that sort of
advice is particularly helpful.
Feb 20 '06 #5
?
ö
---
Posted via DotNetSlackers.com
Nov 28 '06 #6

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

Similar topics

4
by: Edvard Majakari | last post by:
Greetings, fellow Pythonistas! I'm about to create three modules. As an avid TDD fan I'd like to create typical 'use-cases' for each of these modules. One of them is rather large, and I wondered...
3
by: Indraneel Sheorey | last post by:
Hello, I want to set up a query in SQL Server that is "grouped by" a variable PRICE. Since PRICE takes on continuous decimal values, I want to create deciles based on this variable and then...
1
by: santhosh_176 | last post by:
:I Created a Pocket PC application for iPAQ 5450. Every thing went fine even installer creation. I could run the setup and install it into the actual device and worked fine. The application enables...
1
by: Dixie | last post by:
I wish to add some fields to an existing table in code. I am using the following code from rkc. CurrentDb.Execute ("ALTER TABLE MyTable ADD MyNewField Text 25") This works , but I need to also set...
17
by: Lee Harr | last post by:
I understand how to create a property like this: class RC(object): def _set_pwm(self, v): self._pwm01 = v % 256 def _get_pwm(self): return self._pwm01 pwm01 = property(_get_pwm, _set_pwm)
8
by: ctiggerf | last post by:
I was hopeing someone could help me out here. Been stumped on this one all day. This function 1. Checks uploaded files. 2. Creates two resized images from each (a full size, and a...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
5
by: KewlToyZ | last post by:
Good day, I am stuck in a strange situation. SQL 2000 Server, creating a stored procedure to use in Crystal Reports 11. I am trying to build a report without creating a table or temprorary table in...
2
by: slizorn | last post by:
hi guys, i need to make a tree traversal algorithm that would help me search the tree.. creating a method to search a tree to find the position of node and to return its pointer value basically i...
1
by: DarkGiank | last post by:
Hi, im new to csharp and im trying to create a class that can change the application database without no rewriting all connection code... but cause some reason it is not working... it tells me that...
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...
1
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: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: 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.