Introduction

Today we’re talking about the Dictionary data type. Many developers aren’t even aware that it’s available in the Visual Basic language. The reason for that is because you have to reference Microsoft.Scripting.Runtime in order to gain access to it.

Practice

So before we start, right click on your project folder in the solution explorer of Visual Studio and click Add Reference. Then find the Microsoft.Scripting.Runtime namespace in the COM category.

We’re now ready to use the Dictionary Data type. We can declare a new Dictionary object like so:

That wasn’t so hard was it? Let’s go through how to add values to the Dictionary object.

Pretty simple stuff. To call a value based on it’s key name, just type the following:

In the above code, “Key” is the name of our key. One more important thing to remember is that a Dictionary object is susceptible to memory leakage. So whenever you’re done with your Dictionary object you need to clear it out manually like so:

Those were some of the basics for the Visual Basic Dictionary data type. For more methods you can call on Dictionary objects, head over to the MSDN reference site.