List.Exist using Linq

I want to check if any of the items in the list has a field set to true

I'm currently doing this:

 bool isPaid = visit.Referrals.Exists(delegate(AReferral r) { return r.IsPaidVisit; }); 

How can I do this using Linq may be trivial for some, but I can’t understand if now.

+7
source share
1 answer
 using System.Linq; ... bool isPaid = visit.Referrals.Any(r => r.IsPaidVisit); 

but why use the Linq library when you can do the following:

 bool isPaid = visit.Referrals.Exists(r => r.IsPaidVisit); 
+8
source

All Articles