More complex games usually means more complex methods of organization. Dictionaries help you make sense of the chaos by mapping a key (like a string) to a value pair (for example an int) and then giving you a fast way to look it up.

Like in example above use an Item to create a dictionary key pair to find the name of the item using it’s key you can see the results below.

 

The ability to use keys to access items stored in a dictionary simplifies the process significantly and allows you assign meaning to the keys. You can quickly organize large sets of data easily. Much like a list but with greater ability to customize. This makes managing things like a in-game shop or loot tables a snap. You can also use a foreach loop to search a dictionary much like a list using the key.

Here we have the same set up Dictionary but with 2 additional entries. Then we iterate over the foreach using the key/value pair to display them.

Here we remove one of the entries.

Then we re-run the results.

Hopefully this gave you some insight into the kind of versatility that Dictionaries give you. With this you can create complex lists of items, databases, and other collections of objects while still being able to smartly organize and search them while adding and removing items. Until next time, happy coding.