OrderBy().Last() or OrderByDescending().First() performance

前端 未结 6 1979
灰色年华
灰色年华 2020-12-09 14:33

I know that this probably is micro-optimization, but still I wonder if there is any difference in using

var lastObject = myList.OrderBy(item => item.Crea         


        
6条回答
  •  醉话见心
    2020-12-09 15:27

    I'm sorry this doesn't directly answer your question, but...

    Why not do a better optimization and use Jon Skeet's implementations of MaxBy or MinBy?

    That will be O(n) as opposed to O(n log n) in both of the alternatives you presented.

提交回复
热议问题