private double GetProductPrice(Product product) { if (ProductQuantities.TryGetValue(product, out int quantity)) { return(product.Price * quantity); } throw new KeyNotFoundException(nameof(product)); }
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); } }