Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 列表c上的多个条件where#_C#_.net Core - Fatal编程技术网

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);