c# - Return the element of a list which fulfills a certain condition -


i have class:

class point {     double x, y; } 

from list<point>, want point point.x + point.y maximum in list. how in linq?

this 1 way (though not optimal means):

list<point> list = ...; point maxpoint = list.orderbydescending(p => p.x + p.y).first(); 

another way should perform better, involve modifying point class implement icomparable<t>, this:

class point : icomparable<point> {     double x, y;      public int compareto(point other)     {         return (x + y).compareto(other.x + other.y);     } } 

... allow do:

list<point> list = ...; point maxpoint = list.max(); 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -