我有一個XML文件:排序列表numericallyC#
<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「從數字上形成高到低? 我在網上看到了很多東西,但我不明白他們:(
我真的很感激的答案!
謝謝!
我昨天回答了幾乎與此相同的東西.http://stackoverflow.com/questions/17231446/select-top-5-records-from-xml-with-c-sharp/17231588#17231588 – James
你需要採取幾個步驟回,並試圖將其應用到XML文件 –
Youly代碼只添加一個項目到列表之前學習的C#和泛型的基礎知識! –