How can I increment the value of the property TeamSize each time a new Athlete object is added? Because I cannot create a variable to store the value for TeamSize and increment that value each time a new Athlete object so I wonder if there is another way to increment TeamSize.
public class Team
{
private Athlete[] athletes;
public int MaxTeamSize
{
get;
set;
}
public string TeamName
{
get;
set;
}
public static int TeamSize
{
get;
set;
}
public Sport TeamSport
{
get;
set;
}
public Team(string name, Sport sport, int maxTeamSize)
{
TeamName = name;
TeamSport = sport;
MaxTeamSize = maxTeamSize;
athletes = new Athlete[maxTeamSize];
}
public Athlete[] AddAthlete(Athlete a)
{
int teamSize = this.athletes.Length;
if (teamSize < MaxTeamSize)
{
athletes[teamSize] = a;
teamSize++;
TeamSize = teamSize;
}
return this.athletes;
}
}