示例#1
0
文件: Car.cs 项目: vomaufgang/tanms
        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.");
            }
        }
示例#2
0
 //
 public string GetComplimentFor(Passenger passenger) => $"You smell great {passenger}!";