MIN and MAX in C

Where are MIN and MAX defined in C, if at all? They aren’t. What is the best way to implement these, as generically and type safe as possible (compiler extensions/builtins for mainstream compilers preferred). As functions. I wouldn’t use macros like #define MIN(X, Y) (((X) < (Y)) ? (X) : (Y)), especially if you plan … Read more

How to perform .Max() on a property of all objects in a collection and return the object with maximum value [duplicate]

We have an extension method to do exactly this in MoreLINQ. You can look at the implementation there, but basically it’s a case of iterating through the data, remembering the maximum element we’ve seen so far and the maximum value it produced under the projection. In your case you’d do something like: var item = … Read more