How to create key value dictionary in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
	Public Shared Sub Main()
        Dim dict As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer)()
		
        dict("csharp") = 1
        dict("c") = 4
        dict("java") = 6
        
		dict.Add("python", 9)
        
		Console.WriteLine("key values:")
        For Each kvp As KeyValuePair(Of String, Integer) In dict
            Console.WriteLine(kvp.Key & " - " & kvp.Value)
        Next

        Console.WriteLine(Environment.NewLine & "keys:")
        For Each key As String In dict.Keys
            Console.WriteLine(key)
        Next

        Console.WriteLine(Environment.NewLine & "values:")
        For Each val As Integer In dict.Values
            Console.WriteLine(val.ToString())
        Next
    End Sub
End Class





' run:
'
' key values:
' csharp - 1
' c - 4
' java - 6
' python - 9
' 
' keys:
' csharp
' c
' java
' python
' 
' values:
' 1
' 4
' 6
' 9
' 

 



answered Dec 10, 2022 by avibootz
...