作者Cloud (抓不住...)
看板C_Sharp
标题Re: [问题] 如何让SortedDictionary降幂排序
时间Fri Apr 24 15:46:49 2009
※ 引述《gamecubemomo (AMO)》之铭言:
: 我有一个SortedDictionary类别,Key是Double型别
: 只要有项目加进去,他内部都会以升幂的方式帮我们排序好
: 不过我希望能以降密的方式由大到小排列
: 请问有什麽方法可以做到呢?
: 感激不尽~
使用IComparer
Ex:
class DoubleComparer : IComparer<double>
{
public int Compare(double x, double y)
{
if ( X > Y )
return 1;
else
return -1;
}
}
就可以使用如下:
SortedDictionary<double, string> dir =
new SortedDictionary<double,string>(new DoubleComparer());
手上没编译器,但是应该八九不离十~~
--
I want love if it's possible ~~
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 218.174.37.148
1F:推 gamecubemomo:可以了,感恩!!!不过判断的地方要换成x < y才能降幂唷 04/24 21:05