Click here to Skip to main content
15,894,343 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello , i am creating a leaderboard for my windows store app using buddy.com
i am facing a problem in getting the top ten high scores in the leaderboard

var highestScore = highScores.First().Score;

i used this code to get the first score and this worked but when i tried to do this .
var top10 = highScores.Take(10);
           foreach (var myscore in top10) {

               string myresult = myscore.Score.ToString();
               secondscore.Text = myresult;

           }


i get 5 only but i should get a string contain the top 10 scores , what is wrong in my code and how to fix it , thank you
Posted
Comments
Karthik_Mahalingam 29-Jan-14 9:04am    
check this count
var top10 = highScores.Take(10);
int count = top10.Count();

1 solution

Well...it's a little obvious.
What does this code do:
C#
int value = 0;
for (int i = 1; i < 10; i++)
   {
   value = i;
   }
Console.WriteLine(index);
Answer: it prints "9".
Why? Because an integer can contain only one value, so when you say:
C#
value = i;
you discard the previous version.
Now, your code does the same:
C#
foreach (var myscore in top10) {
    string myresult = myscore.Score.ToString();
    secondscore.Text = myresult;
}
Both MyResult and secondscore.Text are strings, so when you assign them a new value, you discard every previous one.

Exactly what you want to do, I'm not sure, but just changing it to:
C#
foreach (var myscore in top10) {
    string myresult = myscore.Score.ToString();
    secondscore.Text += myresult;
}
will show you what I mean.
 
Share this answer
 
Comments
bowlturner 29-Jan-14 9:16am    
Good catch, apparently it's still to early in the morning for me.
OriginalGriff 29-Jan-14 9:30am    
Get coffee - it's the only thing which kick starts my brain as well! :laugh:

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