C#:是否有可能返回一个IOrderedEnumerable< T>? [英] C#: Is it possible to return an IOrderedEnumerable<T>?

查看:108
本文介绍了C#:是否有可能返回一个IOrderedEnumerable< T>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能从一个方法中返回一个 IOrderedEnumerable< T> 而不使用 OrderBy OrderByDescending 方法在 IEnumerable< T>



不是......但是......也许我错了?






原因:主要是好奇心。这只是一种打我时,使此答案有关返回数字中的数字。而且我的方法会按照给定数字中的权重以升序返回数字。所以我认为如果他们按照框架认可的顺序排列,也可能会很好。当然,我们可以争辩说,从一般的观点来看,它们并没有被订购。但是,是的,如果他们应该或不应该不在这里。只要可能或不可以。



我想我也暗示了一个问题(或者至少现在是)如果 IOrderedEnumerable< T> 不仅仅是一个名字不同的 IEnumerable< T> 。它是否包含更多?我知道它有 ThenBy ThenByDescending 方法,但它们是否使用 IOrderedEnumerable< ; T> ,还是只是直接使用 IEnumerable< T>

$如果你想要的话,你可以自己实现 IOrderedEnumerable< T> > ... 它并不是很难,取决于你需要做什么。最简单的选择就是调用 OrderBy / OrderByDescending ,尽管如此:)

你为什么感兴趣?

Is it possible to return an IOrderedEnumerable<T> from a method without using the OrderBy or OrderByDescending methods on an IEnumerable<T>?

Im guessing perhaps not... but... maybe I am wrong?


Reason: Mostly curiosity. It just kind of hit me when making this answer on returning digits in a number. And my method would return the digits in ascending order, according to their weight in the given number. So I thought it could be nice if they came out ordered in a way that the framework would recognize as ordered as well. Of course we can argue that from a common number point of view they were not ordered. But yeah... if they should or shouldn't wasn't the point here. Just if it was possible or not.

I guess I am also kind of implying a question (or am now at least) on if an IOrderedEnumerable<T> is more than just an IEnumerable<T> with a different name. Does it contain anything more? i know it has the ThenBy and ThenByDescending methods, but do they use anything inside the IOrderedEnumerable<T>, or is it just that they don't make sense to use directly on an IEnumerable<T>?

解决方案

Well, you can implement IOrderedEnumerable<T> yourself if you want too... it's not hugely hard, depending on what you need to do. The easiest option is just to call OrderBy/OrderByDescending though :)

Why are you interested?

这篇关于C#:是否有可能返回一个IOrderedEnumerable&lt; T&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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