|
发表于 2020-1-20 18:18:02
|
显示全部楼层
Hashtable ht = new Hashtable();
ht.Add("2","电脑");
ht.Add("1","配件");
ht.Add("9","内存条");
ht.Add("0","机箱");
ht.Add("7","显卡 ");
ht.Add("3","声卡");
System.Collections.ArrayList al = new ArrayList(ht);
al.Sort(new A());
object[] o = al.ToArray();
for(int i=0;i<o.Length;i++)
{
DictionaryEntry de =( DictionaryEntry )o[i];
Response.Write(de.Key +":"+ de.Value +"<BR>");
}
class A:IComparer
{
#region IComparer 成员
public int Compare(object x, object y)
{
// TODO: 添加 A.Compare 实现
DictionaryEntry d1 = (DictionaryEntry)x;
DictionaryEntry d2 = (DictionaryEntry)y;
return Convert.ToInt32(d1.Key) - Convert.ToInt32(d2.Key);
}
#endregion
}
|
|