简体   繁体   English

返回IOrderedEnumerable的方法是否有利? <T> 而不是IEnumerable <T> ?

[英]Can it be advantageous for a method to return IOrderedEnumerable<T> instead of IEnumerable<T>?

返回IOrderedEnumerable而不是IEnumerable的方法是否有利?

Only if you expect people to order that enumerable every time and would find it hard to figure out how to do this OR if you can provide a collection that implements that interface that can efficiently order its contents and is paired with an extension method that is aware of your collection. 只有当你希望人们每次订购可枚举并且很难弄清楚如何做到这一点,或者如果你能提供一个实现该接口的集合,它可以有效地订购其内容并与一个知道的扩展方法配对你的收藏。

Best option is to return a specific collection type (see Richter for details on that). 最佳选择是返回特定的集合类型(有关详细信息,请参阅Richter)。 99 times out of 100 whoever gets even a simple enumerable can use the standard linq extension methods to order it if they want. 即使是简单的枚举,也可以使用标准的linq扩展方法对其进行排序。

具体来说,如果它有进一步的意义,那将是值得做的.ThenBy调用,而不是其他。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM