Skip to main content

Posts

Showing posts with the label HashTable vs Dictionary in C#

HashTable vs Dictionary in C#

Dictionary: 1.        Dictionary throws an exception if we try to find a key which does not exist in current collection. 2.        Dictionary is faster than Hashtable because there is no any boxing and unboxing . For example: In the Dictionary, n o need boxing and unboxing. i.e. var employees = new Dictionary < string , Employee >(); Employee emp = employees [ "Anil Singh" ];                    In the Hashtable, need to boxing and unboxing. i.e. var employees = new Hashtable (); Employee emp = customers[ "Anil Singh" ] as Employee ; 3.        When we creating dictionary , we must declare the data types of both keys and values. 4.        Dictionary is a generic type and type-safe. i.e.        ...