When adding the items to the list, as mentioned in our
introduction, each key must be unique:
you cannot have two exact keys. If you try adding a key that exists already in
the list, the compiler would throw an ArgumentException exception. Based
on this, the following code would not work because, on the third call, a
"Patrick" key exists already:

This means that, when creating a dictionary type of list,
you must define a scheme that would make sure that each key is unique among the
other keys in the list.

Besides the Add() method, you can use the indexed
property to add an item to the collection. To do this,
enter the Key in the square brackets of the property and assign it the
desired Value. Here is an example:

Although, or because, the key and value are distinct, to
consider their combination as a single object, if you are using either the System::Collections::Hasthtable
or the System::Collections::SortedList class, the .NET Framework provides the DictionaryEntry
structure. To access an item, you can use the for each loop to visit each
item.

To support the for each loop, the System::Collections::Hashtable
and the System::Collections::SortedList classes implement the IEnumerable::GetEnumerator()
method. In this case, the item is of type DictionaryEntry: it contains a Key
and a Value in combination.

The DictionaryEntry structure contains
two properties named Key and Value to identify the components of a combination.
Here is an example:

If you are using a generic class, the .NET Framework provides the
KeyValuePair structure that follows the same functionality as the System::Collections::DictionaryEntry
structure, except that you must apply the rules of generic classes.

Practical
Learning: Enumerating the Members of a Collection

Display the Order Processing form

On the form, click the Driver's Lic # text box

In the Properties window, click the Events button and, in the Events
section, double-click Leave