Hashtable in C#

Introduction:

This article explains about hashtable. Hashtable optimizes lookups. It computes a hash of each key you add. It then uses this hash code to look up the element very quickly. It is an older .NET Framework type. It is slower than the generic Dictionary type.




Example:
class Program
{
    static void Main()
    {
 Hashtable hashtable = new Hashtable();
 hashtable[1] = "One";
 hashtable[2] = "Two";
 hashtable[13] = "Thirteen";

 foreach (DictionaryEntry entry in hashtable)
 {
     Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
 }
    }
}
 
Output:
13, Thirteen
2, Two
1, One
Ashwani
Ashwani

This is a short biography of the post author. Maecenas nec odio et ante tincidunt tempus donec vitae sapien ut libero venenatis faucibus nullam quis ante maecenas nec odio et ante tincidunt tempus donec.

No comments:

Post a Comment