C#如何通过它的价值列进行排序排序列表 [英] c# How to sort a sorted list by its value column

查看:184
本文介绍了C#如何通过它的价值列进行排序排序列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通用的排序列表成果与关键=一些文件名和值=布尔值。

i have a generic sorted list "results" with key = some filename and value = boolean.

我想布尔条目或值对列表进行排序柱。没有人知道我可以做到这一点?

I would like to sort the list by the boolean entry or value column. does anyone know how i can do this?

谢谢!

推荐答案

使inertions发生在一个有序的方式排序列表进行了优化,使得枚举发生在以最低成本排序顺序。还有什么需要重新梳理。因此:

SortedList is optimized so that inertions occur in an ordered fashion, such that enumeration occurs in a sorted order at minimal cost. Anything else requires a re-sort. Thus:

        SortedList<string,bool> l=new SortedList<string, bool>();
        l.Add("a",true);
        l.Add("a",false);
        l.Add("b",true);
        l.Add("b",false);
        var orderByVal=l.OrderBy(kvp => kvp.Value);



但此枚举会显著慢来计算,而前期进行,需要额外的存储这样做。

but this enumeration will be significantly slower to calculate, and be performed up-front, requiring extra storage to do so.

根据您的情况可能是更便宜的维护与扭转键/值2 SortedList的实例。

Depending on your situation it might be cheaper to maintain 2 SortedList instances with the key/value reversed.

这篇关于C#如何通过它的价值列进行排序排序列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆