Exemple #1
0
        public void ThrowOut(Passenger passenger)
        {
            if (passenger == null)
            {
                // Nameof expressions
                //
                // -- this
                throw new ArgumentNullException(nameof(passenger));
                //
                // -- takes the place of this
                throw new ArgumentNullException("passenger");
                //
                // -- nameof gets rid of the hardcoded element name, allowing easier name refactorings
            }

            if (this.Passengers.Contains(passenger))
            {
                this.Passengers.Remove(passenger);
            }
            else
            {
                throw new ArgumentException("Alas, you can't throw out who never entered. 'Tis a true pity, I say.");
            }
        }
Exemple #2
0
 //
 public string GetComplimentFor(Passenger passenger) => $"You smell great {passenger}!";