我想对 object.Frequency 的组合框中的项目进行排序。我做了一些研究,然后我上了这门课:
public class CompareByFrequency : IComparer<GenderFrequency>
{
public int Compare(GenderFrequency x, GenderFrequency y)
{
return x.Frequency.CompareTo(y.Frequency);
}
public static void QSFreq(List<GenderFrequency> g)
{
g.Sort(new CompareByFrequency());
}
}
然后,将我的对象放入组合框(未排序)中,我使用:
private void showGenderfreq()
{
cboGenderFreqs.Items.Clear();
foreach (GenderFrequency gf in GenderFrequency.GenderFrequencies(
Bird.getBirdFromCSV(txtFile.Text)))
{
cboGenderFreqs.Items.Add(gf);
}
}
但显然我希望将该组合框排序为频率。现在在哪里:
- Accipiter(2)
- 阿劳达 (1)
- 阿纳斯 (6) ...
它应该是
- 阿纳斯(6)
- Accipiter(2)
- 阿劳达(1)
先感谢您