Which is equivalent to C # of the following Python min / max code:
pairs = [ (2,"dog"), (1, "cat"), (3, "dragon"), (1, "tiger") ]
C # Enumerable.Min seems to be very close. But according to his MSDN document, it always returns the minimum VALUE value (and not the source object). Did I miss something?
EDIT
Pay attention . I'm not inclined to this, sorting first, since sorting (O (nlogn)) is computationally harder than finding a minimum (O (n)).
Also pay attention . The dictionary is also not suitable. It cannot handle cases when there are duplicate keys - (1, "cat") and (1, "tiger").
More importantly, the dictionary cannot handle cases where the elements being processed are a complex class. For example, finding a minimum over a list of animal objects using age as a key:
class Animal { public string name; public int age; }
source share