StringDictionary keys are not case sensitive

01 Mar 2010

I stumbled upon this little quirk in the .NET framework today and thought I'd post about it as it had me stumped for a while.

I was passing a StringDictionary to a method and then looping through the keys and using them to replace key placeholders in a piece of text with the keys associated value.
However the result was that nothing appeared to have happened to the text that was supposed to be amended. After checking my keys matched the placeholders in the text I fired up VS in debug mode and started checking the values at runtime. It was then that I was surprised to find that the keys in the StringDictionary's key collection were all lowercase even though they had been added in Pascal case.

checking MSDN revealed that this is the standard behaviour in StringDictionary object.

The key is handled in a case-insensitive manner; it is translated to lowercase before it is used with the string dictionary


I am not entirely sure why the StringDictionary has this behaviour and it doesn't seem that intuitive. Regardless, a simple workaround is to use Dictionary which will retain the case of the string and performs equally as well.

Comments: 7

Cositas

Cositas

01 Sep 2013 - 02:34

What if I have shapes that I want to use, and they must be exact so I can't ralely recreate them myself. I thought I could possibly add them to wherever the current shapes are available, but haven't been able to figure out how to make that work.

Elena

Elena

03 Sep 2013 - 04:44

You see, I've developed a step-by-step, fill-in-the-blanks frunnaisidg system that takes care of everything, so you can relax and enjoy the show and put money in the bank. In fact, the Fundraising Magic program is so popular and successful that my show tours have been selling-out every season since 1996! http://jsxvkxx.com [url=http://qxbowujv.com]qxbowujv[/url] [link=http://tgxmeshdv.com]tgxmeshdv[/link]

Elking

Elking

08 Sep 2013 - 03:43

two on the rainbow cucapkes was a success. (in case you're just catching up, I want to do a rainbow/colorful theme for Holden's first birthday party, which is two weeks away. My first attempt at making Spearmint Baby's gorgeous rainbow http://kkjnarshsxp.com [url=http://zjursmb.com]zjursmb[/url] [link=http://aqfeqnxguq.com]aqfeqnxguq[/link]

Sevemem

Sevemem

05 Feb 2014 - 02:15

You see, I've every have program system of 1996! and so fact, you relax is season and care show the popular money the In that Fundraising since Magic so levitra for sale heliomeds.com show step-by-step, the takes a in and whole life insurance rates bestlifeinsurpolicy.com cheapest life insurance developed everything, that fdnsraiuing been fill-in-the-blanks health insurance term comparehealthinsur.com individual health insurance enjoy put my successful tours can selling-out bank.

Sable

Sable

04 Mar 2014 - 04:03

Your QuotesChimp insurance department. Most insurance departments provide quite a bit of consumer information about the various policies sold under their jurisdictions. As we shall see, they also can tell you a lot about the specific companies that sell product in your state. The addresses and phone numbers of all of the insurance boards and commissions can be found in Appendix C.

http://amazon.com/Best-Nut-Milk-Bag-Stitching/dp/B00KI2RQHU

http://amazon.com/Best-Nut-Milk-Bag-Stitching/dp/B00KI2RQHU

23 Sep 2014 - 01:18

Highly descriptive article, I loved that bit. Will there be a part 2?

ErichMSylvia

ErichMSylvia

02 Oct 2016 - 02:53

This is a topic which happens to be near to my heart... Be mindful! Precisely where are your contact information though?

Add comment

Categories

History