C# 列表c上的多个条件where#
我需要在列表中的何处添加多个条件,但我不能C# 列表c上的多个条件where#,c#,.net-core,C#,.net Core,我需要在列表中的何处添加多个条件,但我不能 List<Account> accounts = getAccount(); 您可以在这个场景中使用。 它具有您在示例代码中使用的确切And()函数 var query=myList.Where();如果(x){query=query.Where();}列表是一个容器,它没有条件或筛选器。查询由LINQJust提供,只需将条件放入Where中,如下所示:list.Where(item=>item.Id==request.Id&&item.
List<Account> accounts = getAccount();
您可以在这个场景中使用。
它具有您在示例代码中使用的确切And()函数
var query=myList.Where();如果(x){query=query.Where();}
<代码>列表是一个容器,它没有条件或筛选器。查询由LINQJust提供,只需将条件放入Where
中,如下所示:list.Where(item=>item.Id==request.Id&&item.code==request.code&&……
但我需要将它们设置为条件,这就是为什么我可以将它们放入where@DhouhaBenAchour当前位置我明白什么使你困惑。投票决定重新开放。
Func<Account, bool> predicate = X => true;
if (request.id!= 0)
{
predicate = predicate.And(giftCard => giftCard.Id == request.Id);
}
if (request.code> 0)
{
predicate = predicate.And(giftCard => giftCard.code== request.code);
}
if (request.cjn> 0)
{
predicate = predicate.And(giftCard => giftCard.cjn== request.cjn);
}
var resuly=accounts.where(predicate);