Let's create a dictionary to store items that a character might carry:
- Declare a Dictionary with a key type of string and a value type of int, called itemInventory.
- Initialize it to new Dictionary<string, int>(), and add three key-value pairs of your choice. Make sure each element is in its pair of curly brackets.
- Add a debug log to print out the itemInventory.Count property so that we can see how items are stored.
- Save the file and Play:
Here, a new dictionary, called itemInventory, was created and initialized with three key-value pairs. We specified the keys as strings, with corresponding values as integers, and printed out how many elements itemInventory currently holds:
Like lists, we need to be able to do more than just print out the number of key-value pairs in a given dictionary. We'll explore adding, removing, and updating these values in the following section.