我的客户名单:和条件使用LINQ
List<customer> customerList;
我希望得到的只是有国家=“印度”和状态=“A”的客户。
我尝试这样做:
List<customer> customerList=customerList.Where(p=>p.Country.Equals("India") && p.Status.Equals("A")).ToList();
和
List<customer> customerList=customerList.Where(p=>p.Country.Equals("India")).Where(p=>p.Status.Equals("A")).ToList();
但无论是什么返回。
如果我像下面的例子那样划分条件,那么记录被正确提取。
List<customer> customerList=customerList.Where(p=>p.Country.Equals("India")).ToList();
customerList=customerList.Where(p=>p.Status.Equals("A")).ToList();
我想知道如何在单个查询中使用AND条件过滤对象。
任何人都可以告诉,有什么好方法,而不是调用condtion。
您确定至少有一项满足这两个条件吗?您的第一个2个查询对我来说似乎是正确的... – digEmAll
显示您的测试数据,因为2个linq语句在面值上看起来是正确的。 – BugFinder
是“国家”和“状态”字符串变量,还是其他类型的变量? – Servy