I am seeking a better and correct way of initializing Objects which is listed in another object? For example let's say I have two Classes Player and Team and one of properties in the Team class is a generic list of Player as
public List<Player> Players{ get; set; }
How I can Initialize the Player inside initializing the Team? I mean let's assume I do not have any object for Player and want to created them while creating/initializing the Team class object
void Main()
{
}
public class Player
{
public string Name { get; set; } = string.Empty;
public Player(){
Name = string.Empty;
}
}
public class Team
{
public string Name { get; set; }
public List<Player> Players{ get; set; }
public Team(){
Name = string.Empty;
Players = new List<Player>();
}
}
IEnumerable<Player>to theTeam()constructor that it can use to populate the list?