ARTICLE

Changing a key in Collection Class Hashtable in VB.NET

Posted by Sapna Articles | Visual Basic Language August 10, 2010
In this article you will learn how to replace or change a key in Collection class Hashtable in VB.NET.
 
Reader Level:


In VB.Net Hashtable is used to store to both data and object and provides better performance and ability to make more methods and properties available to the programmer. The biggest advantage of the Hashtable is its inheritance feature.
So we can sat that VB.Net collection class Hashtable is quite powerful class in Collections Library. To replace or change key in Hashtable there is no built-in function. So here is simple way to replace or change a key in collection class Hashtable:

Imports System.Collections
Module
Module1
    Sub Main()
        Dim ht As New Hashtable
        ht.Add("AAA", 1111)
        ht.Add("bbb", 2222)
        ht.Add("CCC", 3333)
        For Each ival As String In ht.Keys
            Console.WriteLine(ival + "  =  " + ht(ival).ToString())
        Next
        Dim iTmp As Integer
        iTmp = ht("CCC")
        ht.Remove("CCC")
        ht.Add("ccc", iTmp)
        For Each ival As String In ht.Keys
            Console.WriteLine(ival + "  =  " + ht(ival).ToString())
            Console.ReadLine()
        Next
    End Sub
End Module

OUTPUT:

hashtb.gif

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor