By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,701 Members | 1,978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,701 IT Pros & Developers. It's quick & easy.

Creating a case-insensitive Hashtable in v2

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
"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

P: n/a
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

P: n/a
"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

P: n/a
?

---
Posted via DotNetSlackers.com
Nov 28 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.