views:

1974

answers:

2

Does anyone have any idea what the practical differences are between the System.Collections.Specialized.StringDictionary object and System.Collections.Generic.Dictionary?

I've used them both in the past without much thought as to which would perform better, work better with Linq, or provide any other benefits.

Any thoughts or suggestions as to why I should use one over the other?

+11  A: 

Dictionary<string, string> is a more modern approach. It implements IEnumerable<T> and it's more suited for LINQy stuff.

StringDictionary is the old school way. It was there before generics days. I would use it only when interfacing with legacy code.

Mehrdad Afshari
Are there any performance differences between the two?
thecoop
You should benchmark to see which performs better for your special situation. I don't expect a noticeable performance difference. I recommend using `Dictionary<string,string>` for all new code (unless you need to target 1.1).
Mehrdad Afshari
+4  A: 

I think StringDictionary is pretty much obsolete. It existed in v1.1 of the framework (before generics), so it was a superior version at the time (compared to the non-generic Dictionary), but at this point, I don't believe there are any specific advantages to it over Dictionary.

However, there are disadvantages to StringDictionary. StringDictionary lower-cases your key values automatically, and there are no options for controlling this.

See:

http://social.msdn.microsoft.com/forums/en-US/netfxbcl/thread/59f38f98-6e53-431c-a6df-b2502c60e1e9/

Reed Copsey