今天参与了一个讨论关于对Dictionary排序问题:
http://community.youkuaiyun.com/Expert/topic/5682/5682646.xml?temp=2.558535E-02
小结如下:
- .net framework2.0 可以使用范型对简单数据类型进行比较排序,例如:













- .net framework 1.1不支持反省范型,可以将hashtable中的数字输出到arraylist中然后排序,但要重写ICompare接口。先给出一个例子:























由于ArrayList 排序Sort方法需要传入排序的方式,即Icompare接口。下面根据MSDN上的描述:
http://msdn2.microsoft.com/en-us/library/system.collections.icomparer.compare(VS.71).aspx
http://msdn2.microsoft.com/en-us/library/system.collections.icomparer.aspx
可知:需重写int IComparer.Compare(Object x, Object y)方法。
Return Value
Value | Condition |
---|---|
Less than zero | x is less than y. |
Zero | x equals y. |
Greater than zero | x is greater than y. |
故对以上代码实现了一个ICompare:



















