|
Hashtable ht = new Hashtable ();
ht.Add ("2", "Computer");
ht.Add ("1", "Accessory");
ht.Add ("9", "Memory module");
ht.Add ("0", "Chassis");
ht.Add ("7", "Graphics card");
ht.Add ("3", "Sound Card");
Ranch
System.Collections.ArrayList al = new ArrayList (ht);
al.Sort (new A ());
object [] o = al.ToArray ();
Ranch
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 members
public int Compare (object x, object y)
{
// TODO: add A.Compare implementation
DictionaryEntry d1 = (DictionaryEntry) x;
DictionaryEntry d2 = (DictionaryEntry) y;
Ranch
return Convert.ToInt32 (d1.Key)-Convert.ToInt32 (d2.Key);
}
#endregion
} |
|