Thursday, 27 June 2013

linq difference between any and all [SOLVED]

All() :
All is used to detemine if all elements satisfy a condition.
Any() :
Any tells you whether there are any elements in the sequence at all.

var numbers = new[]{2,4,6,8,9,10,12};
var all = numbers.All(n => n % 2 == 0); // returns false - not all numbers are even
var any = numbers.Any(); // returns true - there sequence contains at least one element

No comments:

Post a Comment