Ejemplo n.º 1
0
 private double GetProductPrice(Product product)
 {
     if (ProductQuantities.TryGetValue(product, out int quantity))
     {
         return(product.Price * quantity);
     }
     throw new KeyNotFoundException(nameof(product));
 }
Ejemplo n.º 2
0
 public void AddItem(Product product, int amount)
 {
     if (product != null && amount > 0)
     {
         if (ProductQuantities.TryGetValue(product, out int productAmount))
         {
             ProductQuantities[product] = productAmount + amount;
             return;
         }
         ProductQuantities.Add(product, amount);
     }
 }