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

霸气de小男生 提交于 2019-12-10 14:04:48

问题


Can it be advantageous for a method to return IOrderedEnumerable instead of IEnumerable?


回答1:


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). 99 times out of 100 whoever gets even a simple enumerable can use the standard linq extension methods to order it if they want.




回答2:


Specifically, it would be worth doing if it makes sense for further .ThenBy calls, and not otherwise.



来源:https://stackoverflow.com/questions/1783830/can-it-be-advantageous-for-a-method-to-return-iorderedenumerablet-instead-of-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!