Click here to Skip to main content
15,892,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm making a passaparola game , at the end of the game i save nickname and score with stream writer as nickname;score

I'm trying to make a leaderboard but dont know how to sort them highest to lowest at or after saving.

Also to display them on labels i wrote this ;

C#
string[] scoreArray;
       string sc = sr.ReadLine();

       scoreArray = sc.Split(';');
       label2.Text = scoreArray[0];
       label3.Text = scoreArray[1];

which writes first line in text file.Anyway how can i sort and write them in labels ?

What I have tried:

didnt try anything i dont know how to sort and then write to labels
Posted
Updated 19-Apr-16 9:51am
v2

1 solution

Easiest way would be to use Linq and OrderBy. Try changing the scoreArray to a class object.

class HighScore
{
    String Name { get; set; }
    Int32 Score { get; set; }
}

List<highscore> highScores = new List<highscore>();

// add code to read each line in a loop
// add code split the name and score
HighScore score = new HighScore() { Name = name, Score = score };
highScores.Add(score);
// end loop

var orderedList = highScores.OrderBy(x => x.Score);
</highscore></highscore>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900