不想自己写排序算法的,可以牺牲些哈希表的性能:这里主要是想按值大小排序
//哈希表排序的变通方法
foreach (DictionaryEntry d in hashtable)
{
aX[i]=d.Key.ToString();
aY[i]=Convert.ToInt32(d.Value);
i++;
}
Array.Sort(aY,aX);
foreach (DictionaryEntry d in hashtable)
{
aX[i]=d.Key.ToString();
aY[i]=Convert.ToInt32(d.Value);
i++;
}
Array.Sort(aY,aX);
for(int j=(aY.Length-1);j>0;j--)
{
ListViewItem listViewItem1 = new ListViewItem(new string[] {aX[j],aY[j].ToString()}, -1, Color.Empty, Color.Empty, null);
listView1.Items.AddRange(new ListViewItem[] {listViewItem1});
}
{
ListViewItem listViewItem1 = new ListViewItem(new string[] {aX[j],aY[j].ToString()}, -1, Color.Empty, Color.Empty, null);
listView1.Items.AddRange(new ListViewItem[] {listViewItem1});
}