Re: LINQ sumWhere
Seems I worked it out....
Code:
_myArray.Sum(a => a.Equals(n) ? a : 0);
or in my case which has an array of objects with an Int32 Value member.
Code:
_myObjectArray.Sum(o => o.Value.Equals(n) ? o.Value : 0);
Is there a neater way?
On another point... does anyone else use the tertiary operator and find that 90% of the time, one of the then/else values is the same as the if value?
Eg (upperbound of a value):
return (a > 25 ? 25 : a);
I always think there should be a binary operator equivelent, so you could remove the ": a" from the end of the above.
Eg:
return (a > 25 ? 25);
should do the same. From my C -> C++ -> C# days, I've always thought this. Maybe my coding style... I don't know...
Last edited by rliq; August 19th, 2009 at 01:33 AM.
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......