The difference between dictionary and dictionary <Tkey, Tvalue>
Can someone tell me the difference between DictionaryBase and generic Dictionary<TKey, TValue> , except that DictionaryBase is an abstract class! Both of them are strongly typed, and I read somewhere that generic classes are better than not common for performance, and should be preferable, so what should DictionaryBase use then? Both classes are almost the same!
Any help would be appreciated
thanks
Dictionarybase is a base class that implements a non-generic IDictionary, while a dictionary is a generic version of a dictionary that implements a common IDictionary. Using generics is preferable to not generics.
I think that would be more useful. When to use generics?
It is generally recommended that you use generic collections, as you immediately benefit from type safety by not requiring the base type of the collection and implement elements specific to a particular type. generic collection types are also usually better than corresponding unrelated collection types (and better than types that are derived from unrelated base collection types) when collection elements are value types because there is no need to insert elements using generics.
Also pass, Introduction to General Features
Common classes and methods combine reusability, type of safety, and efficiency in that their unconventional colleagues cannot. The most commonly used generalizations are used with collections and methods that act on them. Version 2.0 of the .NET Framework class library provides a new namespace, System.Collections.Generic, which contains several new collection classes. It is recommended that all applications designed for the .NET Framework 2.0 and later use new generic collection classes instead of older non-generic counterparts
The reason non-generic collection types are still in the .NET platform is mainly for backward compatibility. Generally, you should use generic collection types whenever possible.
I just finished converting the old DictionaryBase class, which was IXmlSerializable to a generic Dictionary(string, string) .
The most painful difference is that for a general Dictionary<string, string> , when I call this[key] for a key that does not exist, I get an exception because the key does not exist.
On DictionaryBase I return null without exception. This was painful in my case, because the system was filled with code that did not check that the ContainsKey dictionary before trying to get the key value. It became much more painful for me to assume that I had mixed up something with serialization.