Hashtable in Visual Basic .NET

Hashtable is a collection of key-value pair
Key should be unique. If you try to add same key twice you will get error message “Item has already been added. Key in dictionary:”

Look the following example

Code explanation:

Line 14: Hashtable object has been created
Line 15: You can add the grad_student1 object to Hashtable. Key is “S001”

Iterate the Hashtable

Code explanation:

Line 1: We are using Type as DictionaryEntry
Line 2: Casting the element.value to Student

Removing element in Hashtable
You can use remove() by passing the Key as parameter