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

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

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -