2 Replies
Take a look! https://source.dot.net/#System.Linq/System/Linq/Max.cs,6bfc5de59f92263e
E.g. for
int
you end up here: https://source.dot.net/#System.Linq/System/Linq/MaxMin.cs,33. Provided that you're working with something like an array, there are optimized paths for all sortsYes there's a reason this benchmark shows calling the LINQ Max method is significantly faster than the naive loop you might write yourself:
https://github.com/Treit/MiscBenchmarks/tree/main/MaxOfIntArray