Specifying a parameter in C # OrderBy methods

Good morning,

Suppose I have a list of Tuple elements and a function that takes a String and returns a Double, for example. How can I, using any other method, use the list method OrderBywith this function, calculated only on the first coordinate of each tuple? For example return List.OrderBy(FunctionTakingString(Tuple'sFirstCoordinate)).First?

Many thanks.

+3
source share
1 answer

Just do:

return list.OrderBy(x => CustomFunction(x.Item1))
           .First();

OrderByjust a delegate should be provided to calculate the value from the element. Within the delegate, you can do what you want within reason.

+7
source

Source: https://habr.com/ru/post/1771467/


All Articles