I have something like this:
public class Item
{
public int itemID;
public string itemName;
}
public class Tool : Item
{
public int toolDurability;
}
I want to create a Dictionary, something like
public Dictionary<int,Item> itemDic = new Dictionary<int,Item>();
Where the key is the itemID
, and the Item
is the Item
. This way I have a sort of database to give it some itemID
, and it spit back out the appropriate item. The issue is, if I add the class Tool
to this dictionary, if I try accessing the dictionary value, it will not give access to the Tool
variables (since the dictionary only specifies the top-level "item" class).
If I create several different inherited classes, how would I setup a dictionary to allow me to get the correct class / Type of item, out of the dictionary based on its itemID
?