473,729 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(CaseI nsensitiveHashC odeProvider.Def ault,
CaseInsensitive Comparer.Defaul t);

In v2, this generates the following warnings:

Warning 1 'System.Collect ions.CaseInsens itiveHashCodePr ovider' is obsolete:
'Please use StringComparer instead.
Warning 4
'System.Collect ions.Hashtable. Hashtable(Syste m.Collections.I HashCodeProvide r,
System.Collecti ons.IComparer)' is obsolete: 'Please use
Hashtable(IEqua lityComparer) 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 8558
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(CaseI nsensitiveHashC odeProvider.Def ault,
CaseInsensitive Comparer.Defaul t);

In v2, this generates the following warnings:

Warning 1 'System.Collect ions.CaseInsens itiveHashCodePr ovider' is obsolete:
'Please use StringComparer instead.
Warning 4
'System.Collect ions.Hashtable. Hashtable(Syste m.Collections.I HashCodeProvide r,
System.Collecti ons.IComparer)' is obsolete: 'Please use
Hashtable(IEqua lityComparer) 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 IEqualityCompar er<T>. In this
case, you would create a Dictionary<stri ng,Foo> (where Foo is whatever
type your values are) and pass in an instance of StringComparer - eg
StringComparer. OrdinalIgnoreCa se or
StringComparer. CurrentCultureI gnoreCase.

--
Jon Skeet - <sk***@pobox.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
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.co m>
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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
> 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
2758
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 if it would be easy enough to create a code skeleton out of unit test module. Consider the following, though contrived, unit test code snippet: ==========================================================================
3
14993
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 display the average price in each decile. As background, PRICE is a calculated quantity: I divide a table field SLS_DLRS by a field SLS_UNTS to get it. I also want to include an average SLS_UNTS for each decile. So essentially, I want the result...
1
1028
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 syncronization with remote database using merge replication. I found contradictory results while installing the application. I will mention here all the steps that I done while creating and installing setups. Result: Case 1: worked fine. ...
1
3405
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 the Required, Allow Zero Length and Indexed attributes. I have tried but keep getting a syntax error. Also, can I set the default value of a field in code? Has anyone some examples of these. TIA
17
1945
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
2828
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 thumbnail). 3. Returns an array with a bool (false if the upload failed), and an error message.
9
3627
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 to create the dynamic controls in the OnInit stage of the lifecycle. Since data from static controls is not yet available in the OnInit stage I can't know what dynamic control I have to create.
5
2530
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 the database. Not too bad but ugly nonetheless. I succedded in creating the process using multiple stored procedures, but the report takes hours to run in Crystal which more less indicates I failed to get a workable solution. I have a few...
2
2659
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 need to read in a text file... shown below H H,E,L E,B,F B,A,C A,null,null
1
2772
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 im not creating the object but im doing it,,, please help im a newbie to c# using System; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SQLite; using MySql.Data; using MySql.Data.MySqlClient; using...
0
8913
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8761
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.