C#SortedList排序列表怎么样逆序输出

C#分别在集合库和泛型库中有共2套SortedList

以较新的泛型库为例,
SortedList<int, string> l = new SortedList<int, string>();
l.Add(5,"fifth");
l.Add(2, "second");
l.Add(3, "third");
l.Add(1, "first");
l.Add(4, "fourth");
//方法1,加载Linq后,使用扩展Reverse()方法
foreach (KeyValuePair<int, string> kvp in l.Reverse())
Console.WriteLine("K:{0}, V:{1}", kvp.Key, kvp.Value);
//方法2,不用linq,使用枚举器的倒序
foreach (KeyValuePair<int, string> kvp in Enumerable.Reverse(l))
Console.WriteLine("K:{0}, V:{1}", kvp.Key, kvp.Value);

K:5, V:fifth
K:4, V:fourth
K:3, V:third
K:2, V:second
K:1, V:first

转载于:https://www.cnblogs.com/coolsundy/p/3821884.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值