C# sorteddictionary, SortedSet 之类排序集合从大到小排序的简单方法

马歌 2013-02-19 02:40:55
C# sorteddictionary, SortedSet 排序都是从小到大,虽然自己写了一个从小到大的,但是觉得不应该这么麻烦,应该有个参数设定之类的,直接就可以按照从大到小排序,求正解。
...全文
1001 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lshfong 2013-02-19
  • 打赏
  • 举报
回复
自己写吧,以后扩展也容易一些
  • 打赏
  • 举报
回复
这个只能自己写接口了。。。 没发现好办法。 发现好办法共享下。 最近在用
马歌 2013-02-19
  • 打赏
  • 举报
回复
引用 2 楼 catchdream 的回复:
SortedDictionary<int, string> dic = new SortedDictionary<int, string>(); dic.Reverse(); SortedList 也有类似的reverse方法。
Reverse可以,就是不知道是不是当集合很大的时候会不会产生很大的开销。 除了用比较接口之外,看来是没有可选参数,可以直接让他在创建的时候就是从小大到排序了。
马歌 2013-02-19
  • 打赏
  • 举报
回复
hehe,看来只能用这个了。 用comparer接口的我会。 class MySort:IComparer<double> { public int Compare(double x, double y) { if (x > y) { return -1; } else { if (x == y) { return 0; } return 1; } } } public SortedSet<double> score_list; score_list = new SortedSet<double>(new MySort());
catchdream 2013-02-19
  • 打赏
  • 举报
回复
SortedDictionary<int, string> dic = new SortedDictionary<int, string>(); dic.Reverse(); SortedList 也有类似的reverse方法。
bdmh 2013-02-19
  • 打赏
  • 举报
回复
自己定义排序规则
SortedSet<T>(IComparer<T>)
写个IComparer接口也很简单,里面改一下比较方向就是了,而且还可以对方负责的对象进行排序,人家凭什么都给你准备好,提供给你一个默认排序就不错了

110,537

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧