Dictionary<TKey,TValue>


Intro

My notes on the Dictionary class used for storing <key, value> pairs.

 


Tips and Tidbits

 

  • Used to store key/value pairs.

  • Size grows dynamically (as opposed to arrays where you need to specify the size ahead of time).

  • The dictionary is accessed via the key (similar to an array’s index). Therefore, the key cannot be null, but value can be.

  • The values (and keys) must all be the same type. You can’t store a string in one key and an integer in another.

  • The key must be unique (ie, duplicate keys are not allowed).

  • Retrieving a value by using its key is very fast, close to O(1), because the Dictionary<TKey,TValue> class is implemented as a hash table.