Supermarket.Inventory.Get C# (CSharp) Method

Get() public method

Gets the given product from this inventory. The amount returned is equal to the specified quantity or the amount stocked by this inventory; which ever is less. The inventory has an equal amount of product removed.
public Get ( string product, int quantity ) : Product
product string The name of the product to obtain
quantity int The desired amount of product
return Product
        public Product Get(string product, int quantity)
        {
            if (Contains(product))
            {
                // Split the stack
                Product productToGive = items[product].Split(quantity);

                if (items[product].Quantity <= 0)
                {
                    // Remove product if stack is empty
                    items.Remove(product);
                }

                // Recalculate total cost of all items in inventory.
                CalculateTotal();
                return productToGive;
            }

            else
            {
                // Return null if shelf doesn't contain the desired product
                return null;
            }
        }