ARTICLE

Hashtable in VB.NET

Posted by Manish Tewatia Articles | Visual Basic 2010 March 23, 2011
Hashtable is used in VB.NET to perform very fast and deterministic lookups from any key to a previously specified value.
 
Reader Level:

Hashtable collection in VB.NET offers the ability to perform very fast and deterministic lookups from any key to a previously specified value. You store any type of object but you store them in key/value pairs. This way you can retrieve an item by a value instead of a numeric index. Conceptually, you add keys and values together, and then can search the table instantly, or even remove elements. As shown in this tutorial, the Hashtable provides a powerful and optimized lookup mechanism.

hash.gif

Given below example shows you how to create an simple Hashtable.

Example:

Module Module1
   
Sub Main()
       
' Create an HashRecord.
       
Dim Record As Hashtable = New Hashtable
       
Record(1) = "One"
       
Record(2) = "Two"
       
Record(15) = "Fifteen"
       
For Each e As DictionaryEntry In Record
           
Console.WriteLine(e.Key)
           
Console.WriteLine(e.Value)
       
Next
       
Console.ReadLine()
   
End Sub

End
Module

Output Window:

pic1.gif

Happy Learning

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Become a Sponsor