/// <summary> /// finds the oldest player in the team /// </summary> /// <returns>oldest player object</returns> public BasketballPlayer FindOldestPlayer() { BasketballPlayer oldestPlayer = this.players[0]; // finds the oldest player for (int i = 1; i < players.Count; i++) { if (players[i].birthDate < oldestPlayer.birthDate) { oldestPlayer = players[i]; } } return(oldestPlayer); }
/// <summary> /// finds the oldest player of the team /// </summary> /// <returns>a reference to the oldest player object</returns> public List <BasketballPlayer> GetOldestPlayers() { List <BasketballPlayer> oldestPlayersList = new List <BasketballPlayer>(); BasketballPlayer oldestPlayer = FindOldestPlayer(); // lists all oldest players if there are more than 1 foreach (BasketballPlayer player in players) { if (player.birthDate == oldestPlayer.birthDate) { oldestPlayersList.Add(player); } } return(oldestPlayersList); }