C# Do List.Exist使用Linq
我想检查列表中是否有任何项的字段设置为C# Do List.Exist使用Linq,c#,linq,list,exists,C#,Linq,List,Exists,我想检查列表中是否有任何项的字段设置为true 目前,我这样做: bool isPaid = visit.Referrals.Exists(delegate(AReferral r) { return r.IsPaidVisit; }); 使用Linq如何做到这一点对
true
目前,我这样做:
bool isPaid = visit.Referrals.Exists(delegate(AReferral r)
{
return r.IsPaidVisit;
});
使用Linq
如何做到这一点对某些人来说可能微不足道,但现在还不清楚
using System.Linq;
...
bool isPaid = visit.Referrals.Any(r => r.IsPaidVisit);
但是,当您可以执行以下操作时,为什么要使用Linq库:
bool isPaid = visit.Referrals.Exists(r => r.IsPaidVisit);
@你必须使用lambda表达式或委托。我可以问一下为什么不使用lambdas吗?起初我试图使用select语句中的
,我想知道是否也可以这样做。@odyodyodys您不能。至少在不重新定义where
和select