C# Array: Order By Descending, including null values -


i have array of (always 4) objects, need order descending value of object member.
had thought order as

array = array.orderbydescending(p => p.val) 

this fell on when 1 of values null, of course. aiming for, linq not to, is:

array = array.orderbydescending(p => if( p != null ) p.val; else float.minvalue) 

how can accomplish ordering without having delete , later re-add null value? help.

use ternary conditional operator:

array = array.orderbydescending(p => p != null ? p.val : float.minvalue) 

per comments below, reason can't use if/else because body of lambda (the stuff right of p =>) must expression, unless surround whole thing curly braces. illustrate, could use if/else if wanted:

array = array.orderbydescending(p =>  {     if (p != null) return p.val;      else return float.minvalue; }); 

but more verbose.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -