private bool ExistsAlready(List <TeamLeader> inputList, TeamLeader inputTeamLeader) { bool found = false; int index = 0; while (!found && index < inputList.Count) { if (inputList[index].Name == inputTeamLeader.Name) { found = true; } index++; } return(found); }
private void addButton_Click(object sender, EventArgs e) { if (IsInputValid()) { TeamLeader theTeamLeader = new TeamLeader(name, number, shiftNumber, hourlyPayRate, trainingHoursAttended); if (!ExistsAlready(teamLeaders, theTeamLeader)) { teamLeaders.Add(theTeamLeader); teamLeadersListBox.Items.Add(theTeamLeader.Name); ClearAll(); nameTextBox.Focus(); } else { MessageBox.Show(theTeamLeader.Name + " exists already."); ClearAll(); nameTextBox.Focus(); } } }