I am making a quiz game for my computing coursework and I have completed the quiz part of my application and I am currently moving on to my leader board but to do that I need to sort my scores text file which contains the users name, score and time but I am now trying to retrieve these data and display them in a table.
The users' name score and time saves fine into the scores text file but to display these details I first need to order these details by the score.
My test file is organised like this:
username,score,time
userName1,33,12
userName2,-55,33
userName3,34,2
userName4,23,27
userName5,63,72
This is the code that I am currently using but this only works if I have the data in the text file sorted first.
string[] readFile = File.ReadAllLines(file).ToArray();
for (int i = 0; i < 5; i++)
{
string[] userDetails = File.ReadAllLines(file).ToArray();
string username = userDetails[0];
string score = userDetails[1];
// Apply the text of lblUsername1-5 to be what the names
// of the top 5 scorers are in the file.
lblUsername1.Text = userDetails[0].Split(',')[0];
lblUsername2.Text = userDetails[1].Split(',')[0];
lblUsername3.Text = userDetails[2].Split(',')[0];
lblUsername4.Text = userDetails[3].Split(',')[0];
lblUsername5.Text = userDetails[4].Split(',')[0];
// Apply the text of lblScore1-5 to be what the scores
// of the top 5 scorers are in the file.
lblScore1.Text = userDetails[0].Split(',')[1];
lblScore2.Text = userDetails[1].Split(',')[1];
lblScore3.Text = userDetails[2].Split(',')[1];
lblScore4.Text = userDetails[3].Split(',')[1];
lblScore5.Text = userDetails[4].Split(',')[1];
}
So if some one could help me to sort the data in my scores ext file that would be great. Thanks in advance.