C# 按降序排序

发布于 2024-12-05 02:29:08 字数 467 浏览 2 评论 0 原文

如何使用 OrderByDescending ?

我有一个标签,Circles,像这样声明

ReadOnlyCollection<FlangeCircle> Circles

,其中包含一个变量,类型为 double 的直径

我想根据直径对它们进行排序,所以我尝试

FlangeCircle<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);

但这不会通过编译器,但以下是

var query = Circles.OrderByDescending(p => p.Diameter);

为什么是这样以及如何我是否可以用“正确”类型来声明查询?

/斯特凡

How is the OrderByDescending used ?

I have a label, Circles, declared like this

ReadOnlyCollection<FlangeCircle> Circles

which contain a variabel, Diameter of the type double

I want to sort them based on the diamter so I try

FlangeCircle<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);

but that will not go throug the compiler, but the following does

var query = Circles.OrderByDescending(p => p.Diameter);

Why is that and how do I declare query with a "correct" type instead ?

/Stefan

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

や莫失莫忘 2024-12-12 02:29:08

变量的类型是问题所在:

FlangeCircle<FlangeCircle> query = ...

FlangeCircle 作为一种类型没有意义,而且肯定不是 OrderByDescending。您几乎肯定想要:

IEnumerable<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);

或者如果您希望能够对查询执行ThenBy/ThenByDescending运算符:

IOrderedEnumerable<FlangeCircle> query = ...;

The type of the variable is the problem:

FlangeCircle<FlangeCircle> query = ...

FlangeCircle<FlangeCircle> doesn't make sense as a type, and certainly isn't what's returned by OrderByDescending. You almost certainly want:

IEnumerable<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);

Or if you want to be able to perform ThenBy/ThenByDescending operatorions on query:

IOrderedEnumerable<FlangeCircle> query = ...;
迷乱花海 2024-12-12 02:29:08

这将返回一个 IEnumerable,因此:

IEnumerable<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);

This will return an IEnumerable, so:

IEnumerable<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);
眼趣 2024-12-12 02:29:08

变量不应该是 IEnumerable 吗?如

IEnumerable<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);

Shouldn't the variable by IEnumerable? as in

IEnumerable<FlangeCircle> query = Circles.OrderByDescending(p => p.Diameter);
呆° 2024-12-12 02:29:08

尝试使用 IEnumerable查询=...

Try to use IEnumerable<FlangeCircle> query = ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文