Value Property Of Dictionary Class In VB.NET
In this article I explained about Value Property of Dictionary Class.
Values
The Values property gets a collection containing the values in the Dictionary. It returns an object of ValueCollection type. The following code snippet reads all values in a Dictionary.
Imports System.Collections.Generic
Module Module1
Sub Main()
' Create a dictionary with string key and Int16 value pair
Dim StudentDetailList As New Dictionary(Of String, Int16)()
StudentDetailList.Add("Mahesh", 35)
StudentDetailList.Add("Raj", 25)
StudentDetailList.Add("Suresh", 29)
StudentDetailList.Add("Nitin", 21)
StudentDetailList.Add("Aman", 84)
' Read all data
Console.WriteLine("Student Details List:")
Console.WriteLine()
For Each student As KeyValuePair(Of String, Int16) In StudentDetailList
Console.WriteLine("Key: {0}, Value: {1}", student.Key, student.Value)
Next
Console.WriteLine()
' Get and display values
Dim values As Dictionary(Of String, Int16).ValueCollection = StudentDetailList.Values
For Each val As Int16 In values
Console.WriteLine("Value: {0}", val)
Next
Console.WriteLine()
Console.ReadLine()
End Sub
End Module
Output: