471,313 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Edvard Majakari | last post: by
3 posts views Thread by Indraneel Sheorey | last post: by
1 post views Thread by Dixie | last post: by
17 posts views Thread by Lee Harr | last post: by
8 posts views Thread by ctiggerf | last post: by
9 posts views Thread by Tarscher | 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.