StringDictionary class adds the key as lower-cased(hockblogs.net)

submitted by hockmanhockman(505) 2 years, 11 months ago

Hi there, In a project I'm currently developing, we used the StringDictionary (In the System.Collections.Specialized namespace) class frequently for stored key value pairs. I noticed that all my keys were lower-cased. So when checking out the Add method with Reflector, I found out that the key is lower-cased. public virtual void Add(string key, string value) { if (key == null) { throw new ArgumentNullException("key"); } this.contents.Add(key.ToLower(CultureInfo.InvariantCulture), value); } As described on MSDN: The key is handled in a case-insensitive manner; it is translated to lowercase before it is used with the string dictionary. So if you want to use a string as a key and want that key string representation exactly to the same as you stored it, that use the following: // Use the Dictionary<string, string> instead of the StringDictionary, since StringDictionary stores it's key as case-insensitive Dictionary<string, string> items = new Dictionary<string, string>(); Nothing fancy, all standard .NET functionality, but this post is written as a reminder for myself and for you as a visitor of my blog. Hope this is usefull! gr, Robbert

add a comment |category: |Views: 5

tags: another

new Add a live kick counter to your blog >> liveImage

You can even customize the image by choosing your own colors, and then clicking the button below to update the preview and the html code:

  • "Kick It" text
  • "Kick It" background
  • kick count text
  • kick count background
  • border

Simply copy and paste this HTML into your blog post.


Users who kicked this story:
Comments:

No comments so far

information Login or create an account to comment on this story