Vb.Net-Informations.com

  How to VB.Net HashTable




   Categories

    HOME
    VB.NET
    CSHARP

 
   














How to VB.Net HashTable

HashTable stores a Key Value pair type collection of data . We can retrive items from hashTable to provide the key . Both key and value are Objects.

The common functions using in Hashtable are :

Add : To add a pair of value in HashTable

Syntax : HashTable.Add(Key,Value)

Key : The Key value

Value : The value of corrosponding key

ContainsKey : Check if a specified key exist or not

Synatx : HashTable.ContainsKey(key)

Key : The Key value for search in HahTable

ContainsValue : Check the specified Value exist in HashTable

Synatx : HashTable.ContainsValue(Value)

Value : Search the specified Value in HashTable

Remove : Remove the specified Key and corrosponding Value

Syntax : HashTable.Remove(Key)

Key : The argument key of deleting pairs

The following source code shows all important operations in a HashTable


         VB.NET Source Code Download           Print Source Code
         How to VB.Net HashTable - Download
        
VB.Net Tutorial

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, 
	ByVal e As System.EventArgs) Handles Button1.Click
        Dim weeks As New Hashtable
        Dim day As DictionaryEntry
        weeks.Add("1", "Sun")
        weeks.Add("2", "Mon")
        weeks.Add("3", "Tue")
        weeks.Add("4", "Wed")
        weeks.Add("5", "Thu")
        weeks.Add("6", "Fri")
        weeks.Add("7", "Sat")
        'Display a single Item
        MsgBox(weeks.Item("5"))
        'Search an Item
        If weeks.ContainsValue("Tue") Then
            MsgBox("Find")
        Else
            MsgBox("Not find")
        End If
        'remove an Item
        weeks.Remove("3")
        'Display all key value pairs
        For Each day In weeks
            MsgBox(day.Key  "  --  "  day.Value)
        Next
    End Sub
End Class
		

When you execute this program it add seven weekdays in the hashtable and display the item 5. Then it check the item "Tue" is existing or not . Next it remove the third item from HashTable. Finaly it displays all item exist in the HashTable.

VB.NET Collections Related Contents
*     How to use VB.NET ArrayList
*     How to use VB.NET Stack
*     How to use VB.NET Queue
*     How to use VB.NET Arrays
*     How to use VB.NET Dyanamic Arrays
*     How to use VB.NET NameValueCollection

VB.Net Related Topics
*     Microsoft .Net Framework Tutorials
*     VB.NET Language Basics Tutorials
*     VB.NET Program Flow Control Tutorials
*     VB.NET Collections Tutorials
*     VB.NET String Tutorials
*     VB.NET Files Tutorials
*     VB.NET Excel 2007 Tutorials
*     VB.NET Crystal Reports Tutorials
*     VB.NET Communications Tutorial
*     VB.NET ADO.NET Tutorial with source code
*     ADO.NET Data Providers help and Tutorial
*     VB.NET ADO.NET Dataset Tutorial
*     ADO.NET DataAdapter and Dataset
*     VB.NET ADO.NET DataView Tutorial
*     VB.NET Remoting Tutorial
*     VB.NET XML Tutorial
Search here for more CSharp Source Code :

  |  Home   |  SiteMap   |  About   |
net-informations.com (C) 2010 All Rights Reserved