示例#1
0
        public void AddSnack(Snack snack)
        {
            if (snack == null)
            {
                throw new ArgumentNullException(nameof(snack));
            }

            if (this.snacks.Count == this.SnackCapacity)
            {
                throw new InvalidOperationException("The pile is full");
            }

            this.snacks.Add(snack);
        }
示例#2
0
        public void AddSnackToPile(Snack snack, int pileNumber)
        {
            if (snack == null)
            {
                throw new ArgumentNullException(nameof(snack));
            }
            if (pileNumber <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(pileNumber));
            }

            if (this.piles.All(x => x.Number != pileNumber))
            {
                throw new InvalidOperationException("There is no pile with this number");
            }

            this.piles[pileNumber].AddSnack(snack);
        }