Example – phone book

As an example, you will create an application for a phone book. The Hashtable class will be used to store entries where the person name is a key and the phone number is a value, as shown in the following diagram:

The program will demonstrate how to add elements to the collection, check the number of stored items, iterate through all of them, check whether an element with a given key exists, as well as how to get a value based on the key.

The whole code presented here should be placed in the body of the Main method in the Program class. At the beginning, let's create a new instance of the Hashtable class, as well as initialize ...

Get C# Data Structures and Algorithms 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.