How to assign a new value to Hashtable without using the Add method in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections

Public Class Program
	Public Shared Sub Main()
        Dim hashtable As Hashtable = New Hashtable()
        hashtable("key1") = "value1"
        hashtable("key1") = "newValue1"
		
        hashtable("key2") = "value2"
        
		Console.WriteLine(hashtable("key1"))
        Console.WriteLine(hashtable("key2"))

        For Each dic As DictionaryEntry In hashtable
            Console.WriteLine("{0}, {1}", dic.Key, dic.Value)
        Next
    End Sub
End Class



' run:
'
' newValue1
' value2
' key2, value2
' key1, newValue1
' 

 



answered Feb 28, 2025 by avibootz
...