Hashtable in VB.NET

Hashtable is used in VB.NET to perform very fast and deterministic lookups from any key to a previously specified value.
  • 5611

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

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.