What is the difference between Dictionary and Hash table?

 Posted by Bh80prk on 12/21/2012 | Category: C# Interview questions | Views: 24330 | Points: 40


Trying to access an in existent key gives runtime error in Dictionary.
Dictionary is a generic type
Generic collections are a lot faster as there's no boxing/unboxing
Dictionary public static members are thread safe, but any instance members are not guaranteed to be thread safe.
Dictionary is preferred than Hash table

Hash table

Trying to access an in existent key gives null instead of error.
Hash table is a non-generic type
Hash table also have to box/unbox, which may have memory consumption as well as performance penalties.
Hash table is thread safe for use by multiple reader threads and a single writing thread
This is an older collection that is obsoleted by the Dictionary collection. Knowing how to use it is critical when maintaining older programs.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response

More Interview Questions by Bh80prk