Generic HashTable in C#

By
February 12, 2009 | Code Snippets, Thoughts from the team

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!

More like this