我有一个 xml 文件:
<highscore>
<score>
<naam>rake</naam>
<punten>100</punten>
</score>
<score>
<naam>john</naam>
<punten>200</punten>
</score>
</highscore>
并且代码将值放在列表中并显示:
public Highscores()
{
InitializeComponent();
XmlNode node = this.xmlbeheer.Open("Highscores/Highscores.xml");
List<Score> scores = new List<Score>();
foreach (XmlNode score in node.ChildNodes)
{
if (score.Name == "score")
{
Score s = new Score();
foreach (XmlNode child in score.ChildNodes)
{
if (child.Name == "naam")
{
s.Naam = child.InnerText;
}
if (child.Name == "punten")
{
s.Punten = child.InnerText;
}
}
scores.Add(s);
}
}
foreach (Score s in scores)
{
if (n < 5)
{
Label naam = new Label();
naam.Top = 10 + 23 * n;
naam.Text = (n + 1) + ". " + s.Naam;
naam.Left = 0;
pnlScores.Controls.Add(naam);
Label punten = new Label();
punten.Top = 10 + 23 * n;
punten.Text = s.Punten;
punten.Left = 140;
pnlScores.Controls.Add(punten);
}
n++;
}
}
但我的问题是如何从高到低对“punten”进行数字排序?我在网上看到了很多东西,但我不明白它们:(
我真的很感谢答案!
谢谢!!