Wednesday 17 July 2013

Differentiate between 'All' and 'Any' Operators in LINQ.

In LINQ, All operator is  to check whether all the elements met the specific condition or not. While Any operator checks whether there is any element exist in the collection or not.


For Example:

int array={1,2,3,4,5};

bool result=array.All(i=>i < 6); here it will check the elements and returns true.

Similarly,

bool result= array.Any( ); // here it checks whether the collection has any elements and returns true.


Hope you Enjoyed!

No comments:

Post a Comment