开发者

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

开发者 https://www.devze.com 2022-12-12 01:22 出处:网络
Can it be advantageous for a method to return IOrderedE开发者_Go百科numerable instead of IEnumerable?

Can it be advantageous for a method to return IOrderedE开发者_Go百科numerable instead of 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). 99 times out of 100 whoever gets even a simple enumerable can use the standard linq extension methods to order it if they want.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消