gpt4 book ai didi

c# - 如何在 LINQ 查询语法中进行最大聚合?

转载 作者:行者123 更新时间:2023-11-30 15:21:59 25 4
gpt4 key购买 nike

LINQ 方法语法

var methodSyntax = VersionControls.Where(x => !x.Removed).Max(x => x.VersionID);

LINQ 查询语法

var querySyntax = from x in VersionControls
where !x.Removed
// how to do Max Aggregation in LINQ query syntax???
select x;

最佳答案

MSDN 文档说 Query Syntax and Method Syntax in LINQ

Query syntax and method syntax are semantically identical, but many people find query syntax simpler and easier to read. Some queries must be expressed as method calls. For example, you must use a method call to express a query that retrieves the number of elements that match a specified condition. You also must use a method call for a query that retrieves the element that has the maximum value in a source sequence.

查询语法不能表达方法语法所能表达的一切

检查如何将它们组合成最小值和最大值 in this answer

var mixedSyntax = (from x in VersionControls
where !x.Removed
select x).Max(x => x.VersionID);

关于c# - 如何在 LINQ 查询语法中进行最大聚合?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36493003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com