PC Review


Reply
Thread Tools Rate Thread

Check hashtable keys by ignoring the case

 
 
Srikanth
Guest
Posts: n/a
 
      12th Jan 2005
Hi

Can any one say how to check a hashtable by ignoring the case of key
supplied. I want the following requirement

It should not allow the user to do the following
Hashtable table = new Hashtable();
a) table.Add("one",1);
b) table.Add("One",1);

by default it executes the above two statements with out any
problem. But my intention is to throw an exception when the table contains
the key by ignoring the case. Is there any way to implement like above?


Thanks in advance

Srikanth


 
Reply With Quote
 
 
 
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      12th Jan 2005
Srikanth,

What you want to do is call the constructor that takes an IComparer,
passing a CaseInsensitiveComparer instance. Then, when you call Add with
the same key, it will throw an exception.

It should be noted that particular constructor is marked as Obsolete in
..NET 2.0, in favor of a new interface (only available in 2.0).

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Srikanth" <(E-Mail Removed)> wrote in message
news:eXLLkKL%(E-Mail Removed)...
> Hi
>
> Can any one say how to check a hashtable by ignoring the case of key
> supplied. I want the following requirement
>
> It should not allow the user to do the following
> Hashtable table = new Hashtable();
> a) table.Add("one",1);
> b) table.Add("One",1);
>
> by default it executes the above two statements with out any
> problem. But my intention is to throw an exception when the table contains
> the key by ignoring the case. Is there any way to implement like above?
>
>
> Thanks in advance
>
> Srikanth
>
>



 
Reply With Quote
 
Carlos J. Quintero [.NET MVP]
Guest
Posts: n/a
 
      12th Jan 2005
You must convert keys to upper case (or lower case) before storing them...

--

Carlos J. Quintero

MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
You can code, design and document much faster.
http://www.mztools.com


"Srikanth" <(E-Mail Removed)> escribió en el mensaje
news:eXLLkKL%(E-Mail Removed)...
> Hi
>
> Can any one say how to check a hashtable by ignoring the case of key
> supplied. I want the following requirement
>
> It should not allow the user to do the following
> Hashtable table = new Hashtable();
> a) table.Add("one",1);
> b) table.Add("One",1);
>
> by default it executes the above two statements with out any
> problem. But my intention is to throw an exception when the table contains
> the key by ignoring the case. Is there any way to implement like above?
>
>
> Thanks in advance
>
> Srikanth
>
>



 
Reply With Quote
 
Nicholas Paldino [.NET/C# MVP]
Guest
Posts: n/a
 
      12th Jan 2005
That would require excessive maintinence. You can use a
CaseInsensitiveComparer (passed through the constructor) which would treat
the keys in a case-insensitive manner.


--
- Nicholas Paldino [.NET/C# MVP]
- (E-Mail Removed)

"Carlos J. Quintero [.NET MVP]" <(E-Mail Removed)> wrote in
message news:u$U9qVL%(E-Mail Removed)...
> You must convert keys to upper case (or lower case) before storing them...
>
> --
>
> Carlos J. Quintero
>
> MZ-Tools 4.0: Productivity add-ins for Visual Studio .NET
> You can code, design and document much faster.
> http://www.mztools.com
>
>
> "Srikanth" <(E-Mail Removed)> escribió en el mensaje
> news:eXLLkKL%(E-Mail Removed)...
>> Hi
>>
>> Can any one say how to check a hashtable by ignoring the case of key
>> supplied. I want the following requirement
>>
>> It should not allow the user to do the following
>> Hashtable table = new Hashtable();
>> a) table.Add("one",1);
>> b) table.Add("One",1);
>>
>> by default it executes the above two statements with out any
>> problem. But my intention is to throw an exception when the table
>> contains
>> the key by ignoring the case. Is there any way to implement like above?
>>
>>
>> Thanks in advance
>>
>> Srikanth
>>
>>

>
>



 
Reply With Quote
 
Mike Scott
Guest
Posts: n/a
 
      12th Jan 2005
The easiest way:
System.Collections.Specialized.CollectionsUtil.CreateCaseInsensitiveHashtable()

"Srikanth" <(E-Mail Removed)> wrote in message
news:eXLLkKL%(E-Mail Removed)...
> Hi
>
> Can any one say how to check a hashtable by ignoring the case of key
> supplied. I want the following requirement
>
> It should not allow the user to do the following
> Hashtable table = new Hashtable();
> a) table.Add("one",1);
> b) table.Add("One",1);
>
> by default it executes the above two statements with out any
> problem. But my intention is to throw an exception when the table contains
> the key by ignoring the case. Is there any way to implement like above?
>
>
> Thanks in advance
>
> Srikanth
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a case-insensitive Hashtable in v2 Mark Rae Microsoft C# .NET 5 28th Nov 2006 02:43 PM
'case Keys.Control | Keys.C:' ---> Doesn't work on 2.0???! Udi Microsoft C# .NET 1 3rd Aug 2006 02:42 PM
Ignoring case on SELECT WHERE... =?Utf-8?B?RGVubmlz?= Microsoft Access Form Coding 8 28th Apr 2005 11:24 PM
Hashtable without keys? cody Microsoft Dot NET Framework 32 26th Apr 2004 10:18 PM
Hashtable keys Jim Hooker Microsoft C# .NET 1 28th Jul 2003 11:33 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:27 AM.