Top Ten Players (2)

Back to our main class.

public static List<Player> GetTopTenPlayers(List<Player> players)
{
    // sort players
    players.Sort(new PlayerComparer());

    // create list for 10 players only
    var topTenPlayers = new List<Player>();

    // looping and add 10 players to list

    // return it
    return topTenPlayers;
}
public static List<Player> GetTopTenPlayers(List<Player> players)
{
    // sort players
    players.Sort(new PlayerComparer());

    // create list for 10 players only
    var topTenPlayers = new List<Player>();
    var i = 0;

    // looping and add 10 players to list
    foreach (var player in players)
    {
        topTenPlayers.Add(player);
        i++;

        if (i == 10)
            break;
    }

    // return it
    return topTenPlayers;
}

We have done with this function. Let's go to our Main method.

var topTenPlayers = GetTopTenPlayers(players);

foreach (var player in topTenPlayers)
    Console.WriteLine(player.FirstName + " - " + player.PointsPerGame);

Something's weird. Isn't it?

Try to fix your own code.

results matching ""

    No results matching ""