public void AddApple(Apple apple, int position) { if (_apples[position] != null) { throw new ArgumentException("Compartment already occupied", nameof(position)); } if (apple == null) { throw new ArgumentNullException(nameof(apple)); } if (position < 0 || position > _apples.Length - 1) { throw new IndexOutOfRangeException("Cannot add apple outside compartments"); } apple.MoveToBox(this, position); }
public int GetApplePosition(Apple apple) { return(Array.IndexOf(_apples, apple)); }