title: Accessing methods of a child object, through a Dictionary
body: <p>New programmer, using C# and VB 2015, first time post so please be gentle!</p>
  
  <p>Basically I am using Dictionary for the first time, and I am trying to access the method useMedPack() which inside my MedPack class, which is a child of Item, which is being created when adding it to my Dictionary. The problem is that it says:</p>
  
  <p>****EDIT**** I feel like I should have added the Item class in first time round (now added to the bottom). Following some awesome suggestions, I casted using   ((MedPack)inventory["MedPack"]).useMedPack(); and it now works as intended! Although some of the feedback has been great and I have learned a lot from everyones suggestions! :)</p>
  
  <blockquote>
    <p>'Item' does not contain a definition for useMedPack();.</p>
  </blockquote>
  
  <pre><code>namespace ConsoleApplication1
  {
      class Program
      {
          static void Main(string[] args)
          {
              Dictionary&lt;String, Item&gt; inventory = new Dictionary&lt;String, Item&gt;();
  
              inventory.Add("MedPack", new MedPack("MedPack", 1));
  
              MedPack.pickUpMedPack(inventory);
  
              //THIS IS THE PROBLEM inventory["MedPack"].useMedPack();
  
              Console.WriteLine("Press any key to exit");
              Console.ReadKey();
  
          }
      }
  }
  
  namespace ConsoleApplication1
  {
      class MedPack : Item
      {
  
          private int healthReturn = 10;
  
          public MedPack() : base()
          {
  
          }
  
          public MedPack(String itemName, int itemQuantity) : base(itemName, itemQuantity)
          {
  
          }
  
          public void useMedPack() 
          {
              decreaseQuantity(1);
          }
  
          public static void pickUpMedPack(Dictionary&lt;String, Item&gt; inventory)
          {
  
              if (!inventory.ContainsKey("MedPack"))
              {
  
                  inventory.Add("MedPack", new MedPack("MedPack", 1));
  
                  Console.WriteLine("You found a MedPack! It was added to the inventory");
  
  
              }
              else
              {
  
                  inventory["MedPack"].increaseQuantity(1);
  
                  Console.WriteLine("You found ANOTHER MedPack! It was added to the inventory");
  
              }
          }
      }
  }
  </code></pre>
  
  <p>namespace ConsoleApplication1
  {
      class Item
      {</p>
  
  <pre><code>    private String itemName;
      private int itemQuantity;
  
  
      public Item(String itemName, int itemQuantity)
      {
  
          this.itemName = itemName;
          this.itemQuantity = itemQuantity;
  
      }
  
      public Item()
      {
  
      }
  
      public void increaseQuantity(int increaseQuantity)
      {
  
          this.itemQuantity += increaseQuantity;
  
      }
  
      public void decreaseQuantity(int increaseQuantity)
      {
  
          this.itemQuantity -= increaseQuantity;
  
      }
  
  
      public String getName()
      {
  
          return this.itemName;
      }
  
      public void setName(String name)
      {
  
          this.itemName = name;
  
      }
  
      public int getQuantity()
      {
  
          return this.itemQuantity;
      }
  
      public void setQuantity(int x)
      {
  
          this.itemQuantity = x;
  
      }
  
  }
  </code></pre>
  
  <p>}</p>