Comparing A list within a list

Hello!

I have A list Called Teams with a type of “TeamSetupDefinition” ;

public List<TeamSetupDefinition> Teams = new List<TeamSetupDefinition>();

TeamSetupDefinition contains

public int Team;
public Color AccsentColor;
public bool IsAi;

public List<Player> Players Team;

I would like to compare the “PlayersInTeam” length against one another, but can’t figure out how to do that.

I’m still relatively new to coding any help would be much appreciated, sorry if my english is hard to read or understand.

You can use List.Sort () :

Teams.Sort ( (f1, f2) => f1.PlayersInTeam.Count.CompareTo (f2.PlayersInTeam.Count) );

You may also use Linq, which is pretty powerful :

using System.Linq
var smallestTeam = ( from item in Teams
			where item.PlayersInTeam.Count > 0
			orderby item.PlayersInTeam.Count
			select item ).FirstOrDefault();