Changing a key in Collection Class Hashtable in VB.NET
In this article you will learn how to replace or change a key in Collection class Hashtable in VB.NET.
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:
