Skip to content

Generic HashTable in C#

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!