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!

By Adam Pope

Founder of Storm Consultancy and web developer. I spend most of my time building bespoke systems for clients in either C# ASP.NET MVC or Ruby on Rails.

storm-consultancy.com →

74posts

Add your comment

Your email address will not be published. Required fields are marked *

*