Storm Blog

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!

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>