Both dictionary and hashtable can be used to stored key/value pairs. But what is the difference between them? When one will be used over other?
Dictionary provides generic types <T Key, T Value> , which allows to create dictionary of any type. Where as HashTable will store values in the form of object. So, while using a collection of primitive types such as integer, hashtable will have additional cost of boxing and unboxing, where as dictionary is generic, it will not have additional cost of boxing and unboxing.
<T Key, T Value>
If the collection if of type int,datetime,float etc, Dictionary provides better performance than hashtable.
If the collection is of type custom object, Both will provide same performance.
ASP.NET Interview questions · · · ·
This comment is waiting for moderation.