O'Reilly logo

C# 4.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hash Tables

A hash table provides key/value pairing with support for efficient lookup by key. Being nongeneric, key and value are represented as System.Object. An exploratory example is shown here:

var tbl = new Hashtable();tbl.Add("Bart", 26);tbl["John"] = 62;bool bartIsKnown = tbl.ContainsKey("Bart");bool someIsAged62 = tbl.ContainsValue(62);foreach (string name in tbl.Keys)    Console.WriteLine("Age of {0} is {1}", name, tbl[name]);tbl.Remove("Bart");

Internally, keys are hashed by use of the key type’s GetHashCode implementation. The idea of a hash code is to provide an integer-valued identifier for an object with as good uniqueness properties as possible. Whenever an entry is requested from the table by using a key, the hash code of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required