Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do List.Exist using Linq

Tags:

c#

list

linq

exists

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

at the moment I do this:

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

How can I do this using Linq might be trivial to some but can't figure if now.

like image 684
Odys Avatar asked May 07 '12 07:05

Odys


1 Answers

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);
like image 63
Lasse Espeholt Avatar answered Oct 24 '22 10:10

Lasse Espeholt