Difference Between Any and Exsits in LINQ

Difference Between Any and Exists in Linq

IEnumerable introduces quite a number of extensions to it which helps you to pass your own delegate and invoking the resultant from the IEnumerable back. The Func plays the important role here.

The Func takes an argument T and returns TResult.

Lets consider you have 1,4,5,1,5,7 as IEnumerable and you write .where(h => h<5) it will return a new IEnumerable of 1,4.

Any - Func basically is similar in signature but returns true only when any of the criteria returns true for the IEnumerable. In our case, it will return true as there are few elements present with h<5.

Exists - Predicate on the other hand will return true only when any one of the predicate returns true. So in our case if you pass .Exists(h => 5) will return true as 5 is an element present in IEnumerable.

Ebook Download
View all
Learn
View all