The Dictionary(Of TKey, TValue) Collection

The System.Collections.Generic.Dictionary(Of TKey, TValue) collection is the generic counterpart for the HashTable. Each item within a Dictionary is a key/value pair; therefore, the constructor requires two arguments (TKey and TValue) where the first one is the key and the second one is the value. The following code shows instantiating a Dictionary(Of String, Integer) in which the String argument contains a person’s name and the Integer argument contains the person’s age:

Dim peopleDictionary As New Dictionary(Of String, Integer)peopleDictionary.Add("Alessandro", 37)peopleDictionary.Add("Stephen", 27)peopleDictionary.Add("Rod", 44)

A single item in the collection is of type ...

Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.