- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
谁能帮我拆开这里的元素并帮助我理解它们是什么?
public static IOrderedEnumerable<TSource> OrderByDescending<TSource, TKey>(
this IEnumerable<TSource> source,
Func<TSource, TKey> keySelector
)
什么是TSource和TKey?什么是键选择器? IOrderedEnumerable 到底是什么?
Func<> 是做什么的??
为什么 MSDN 如此神秘?
最佳答案
分解
Func<TSource,TKey>
: 代表将返回集合中给定元素的键这个函数本质上是一个排序函数。因此,它需要一种方法来比较集合中的元素。这个特定的方法假定对于给定的对象,有一个相应的键值可以用来对它们进行排序。
以下面这个类(class)Student为例
class Student {
string Name { get; set; }
...
}
如果我想对 Student
的集合进行排序通过他们的名字实例我可以做以下事情
IEnumerable<Student> col = GetTheStudents();
var ordered = col.OrderByDescending( x => x.Name );
在这种情况下,值如下
Student
String
Func<TSource,TKey>
: 这是传入的 lambda 表达式 x => x.Name
关于c# - OrderByDescending() 根据 MSDN,这到底是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1827224/
如何使用 OrderByDescending? 我有一个标签 Circles,声明如下 ReadOnlyCollection Circles 其中包含一个变量,类型为 double 的直径 我想根据直
我有一个整数集合,我想按降序排序,但将 0 值保留为列表中的第一个。 例如: 0,1,2,3,4,5,6,7,8 应该导致: 0,8,7,6,5,4,3,2,1 谢谢! 最佳答案 var input
我正在使用 swift 和 parse。我使用了“query.orderbyDescending”,但在某种程度上它不能完美工作。我想排列人们的总分,但顺序如下(例如,9、7、32、21、15....
我有一个父列表,其中包含多个相同类型的子列表,我需要对父列表中的每个列表处理 OrderByDescending 函数。我知道这很困惑,所以你开始吧: public class Message {
以下按顺序返回文件夹 03-march 05-may 我怎样才能修改下面的代码来获得反序 05-may 03-march 代码: private void loadGrid() { List
您好,我正在尝试 OrderByDescending() 查询,而不是: results = results.OrderByDescending(o => o.Surname); 我想使用: res
private static void findNewestFile(List list) { foreach (string dir in list) { var d
在浏览 Enumerable 类的 .Net Framework 源代码时,我发现它的内部 EnumerableSorter 类 CompareKeys method用于排序的有以下一行: retur
我有两个名为 Followers 和 Posts 的类,我正在尝试制作主屏幕,通过它我可以看到我所在用户的帖子以下,还有我的帖子..所以我尝试这样做来获取帖子的查询: func loadData()
我正在使用 LINQ 查询按日期降序获取数据顺序。但是当年份改变时,日期的降序排列不正确 这是我的代码 在此代码中,LastLogin 是具有 DateTime 数据类型的列。我必须按此列名对数据进行
我有一个包含两个可为 null 的日期时间列 ETA 和 ETD 的表。一个总是有值(value)的。我想按日期订购餐 table 。因此,例如,如果 ETA 为空,则使用 ETD 进行订购。如果
我想得到一个列表,该列表按优先级为 3 个属性排序 截止日期 数量 运行日期 我的代码在这里 MyList .OrderByDescending(p => p.ToDate) .Ord
我有一个检索当前用户和他们在我的 feed 页面上的好友列表帖子的查询,我尝试按帖子的创建日期或最新日期对帖子进行排序。这是我在打印“createAt”时从我的代码中得到的结果: 结果非常随机。 这是
我的数据库中有一个包含 DateTime? 的字段。我想对结果进行排序,以便 NULL 显示在顶部,然后按 DateTime 降序排列,例如, null null 2012-04-01 2012-01
我有以下代码,它将返回特定给定 Azure 存储路径的所有列表项(文件和文件夹)。 我想使用基于 Property LastModified 的 OrderByDescending 对其进行过滤 如何
在 lambda 表达式中,如何按 DateTime 值列表而不是对象进行排序?例如,我想通过以下查询获取最近的 3 个发薪日期: var hires = (from e in md.Employe
这个问题在这里已经有了答案: Linq OrderBy does not sort a List. How do I sort the list? (5 个答案) 关闭 2 年前。 我正在使用 Li
正如标题所说,我正在尝试为 source.OrderByDescending(this source, expression, comparer) 构建一个表达式树 这是我生成表达式树的代码: var
我正在尝试构建一个查询,其中有一个学生姓名,然后是他所属的俱乐部的嵌套集合。我想用 OrderByDescending 来组织这个集合。我对向括号提供什么感到困惑。 public void GetSt
我想按数量总和的降序对值列表进行排序,而不覆盖数量的原始值。 因此,假设我的数据列表是: Reason=Quality, Quantity=10 Reason=Quality, Quantity=10
我是一名优秀的程序员,十分优秀!