News & Views.

The latest news, web designs and digital projects happening at Storm.

Sharing is caring:

Generic HashTable in C#

Adam Pope Profile Image

Adam Pope
February 12, 2009

I had a bit of a brain fail earlier and couldn’t remember how to create a HashTable with generic type arguments. There was a Hashtable and a HashSet<> but neither were what I was looking for.  The answer was a Dictionary:

 var myHashTable = new Dictionary<TKey, TValue>

Where TKey is the type of your key (possibly an int to represent the Id of your object or string for a username) and TValue is the type of the value. I hope that saves you some time!