Dictionary in vb.net
How to VB.Net Dictionary
A Dictionary class is a data structure that represents a collection of keys and values pair of data. Each item is a combination of a key and a value. ( key-value pair)
- TKey - The type of the keys in the dictionary.
- TValue - The type of the values in the dictionary.
Adding Values to Dictionary
Add method in Dictionary takes two parameters, one for the key and one for the value.
Key in a Dictionary should not be null, but a value can be, if TValue is a reference type.
Retrieve Key-Value pair from Dictionary
We can retrieve values from Dictionary using foreach loop
Search for a Key
We can search a Key in Dictionary by using the ContainsKey method to test whether a key exists or not. ContainsKey computes the hashcode for its argument and checks the internal structures in the Dictionary.
Iterate over a Dictionary
There are many different ways to iterate over a Dictionary in VB.Net. From the following link you can see in detail .... How to Iterate over a Dictionary
Dictionary Versus HashTable
Dictionary is a generic type, Hashtable is not. That means you get type safety with Dictionary, because you can't insert any random object into it, and you don't have to cast the values you take out. Since both Dictionary and Hashtable are internally hashtables, so fast access to many-item data according to key, also both need immutable and unique keys. More about.... Dictionary Vs HashTable
Dictionary Versus List
Both lists and dictionaries are used to store collections of data. The Dictionary is based on a hash table, that means it uses a hash lookup, which is a rather efficient algorithm to look up things, on the other hand, a list you have to go element by element until it finds the result from beginning to the result each time. More about.... Dictionary vs List
Following vb.net program is a full source code of adding and retrieving key values pairs in Dictionary